You bind them to a callback function that actually moves your element
around. Like so:

function docmove(ev) {
  // use ev (event object) to get current mouse position, compare to
original
  // move element based on difference
}

$("#someTargetElement").mousedown(function(ev) {
  // use ev to get starting mouse position, save for later comparison
  // also, save current position of element you're going to move
  $(document).bind("mousemove", docmove);
});

$(document).bind("mouseup", function() {
   $(document).unbind("mousemove", docmove);
});

As far as actually moving the element, the simplest thing you can do is set
it to absolute position, then set the element's top and left using .css().

- Richard

On Fri, Jul 25, 2008 at 3:18 AM, Nathan Cox <[EMAIL PROTECTED]> wrote:

>
> Hi, I've been trying to do this same thing (move a draggable around by
> clicking on something else) but I can't figure out Richard's
> suggestion.  He says to "bind document.mousemove and document.mouseup"
> but I can't figure out what to bind it to...what exactly do I need to
> put in the callback?  Nothing seems to work...
>
> Thanks,
> Nathan
>
> On Jul 9, 1:49 pm, "Richard D. Worth" <[EMAIL PROTECTED]> wrote:
> > I would recommend the following:
> >
> > 1. On element.mousedown, bind document.mousemove and document.mouseup.
> > 2. On document.mouseup, unbind mousemove and mouseup.
> > 3. Don't worry about sending the drag events (mousemove) to the element
> > that's actually going to be moving, just handle the events at the
> document
> > level and move the element accordingly.
> >
> > This is known as event delegation. Especially because your original
> element
> > isn't going to move, your safest element is document, to which all others
> > will bubble up.
> >
> > You might want to take a look at the mouse plugin inside jQuery UI's core
> > (ui.core.js). This is how it's designed. For examples of use, see any of
> > jQuery UI's draggable, slider, selectable, sortable. After mousedown (on
> the
> > target element), everything else is on the document.
> >
> > - Richard
> >
> > Richard D. Worthhttp://rdworth.org/
> >
> > On Tue, Jul 8, 2008 at 4:52 PM, JohnC <[EMAIL PROTECTED]> wrote:
> >
> > > Can I (and if so, how) drag an element without actually mouse-downing
> > > and -moving on the element I want to move?
> >
> > > For reasons I will happily explain, the user can't actually click on
> > > the object I want them to drag.
> >
> > > So can I get them to click on something else and then have that pass
> > > the dragging info to the real draggable element?
> >
> > > (Just to be clear, the proxy mustn't move - I just want the events of
> > > mousedown/drag to be forwarded to the real draggable element).
> >
> > > Many thanks.
> >
> > > Regards
> >
> > > John
>

Reply via email to