[Javascript] Moving elements

Andrew Gibson andyg at ihug.co.nz
Tue Apr 1 14:26:02 CST 2003


>>>>>>
The most gruesome part (for either Netscape or IE) is to build the
eventHandler
routines for the mouseDown, mouseUp, and drag events, and tie them to
incremental
offset changes made to the position of the layer's reference corner.  To
avoid
overflowing the eventHandler cache, you have to 'debounce' the mouse
movements
by polling the mouse position every 50 to 100 msec or so (using setTimeout),
but
only during the 'drag' stage of the mouse transit.
>>>>>>

I just used the onmousemove event and then had the script calculate the
mouse position using
window.event.clientX  and window.event.clientY then move the element during
the move. But at the start when you move the element the cursor jumps to the
corner of the element, so you have to do an initial offset calculation to
fix that.

As David says, there are further tricky bits like identifying when to stop
the drag, where to drop the item etc etc.

I think theres a sample here on my site

www.dscript.net.nz

then select display, dragging

But couldn't get it working smoothly in NS , mind you that was a year or so
ago.

Andrew Gibson





More information about the Javascript mailing list