da********@gmail.com said on 31/03/2006 11:54 AM AEST:
I am working on a drag/drop script and what I am trying to do is change
the background of a div tag if I move the mouseover it while doing the
drag and drop.
Does anyone know of a script/know how to detect what elements are on a
web page, givin only the co-ordindates of event.pagex and event.pagey ?
You can't ask the browser what DOM objects are above/below some point.
You have to get the location and coverage of objects on your page and
store them - and update them whenever they change.
As you drag stuff around, check whether you are over one of your
registered zones. The usual trick is add a body onmousemove attribute
when you get a mousedown from a 'draggable' object, then remove it when
the object is 'dropped'. The rough algorithm is:
onload, find and register all the draggable and droppable elements.
Whenever you get a mousedown on a draggable element, monitor where the
cursor goes until you get a mouse up. Probably move a representation of
the draggable object in sync with the cursor position.
While the mouse button is down, if the cursor goes over a drop zone, let
the user know.
When the draggable object is dropped, work out what to do based on
whether it was over a drop zone at the time or not. Usually if it was
not over a drop zone, return it to its original position. If it was
over a drop zone, do something else.
--
Rob