dave.wayne@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.

Signature
Rob
dave.wayne@gmail.com - 31 Mar 2006 06:25 GMT
Thanks for your response. part of the fun I am having is the elements
are not on the page when the onload event is fired.
RobG - 31 Mar 2006 08:01 GMT
dave.wayne@gmail.com said on 31/03/2006 3:25 PM AEST:
> Thanks for your response. part of the fun I am having is the elements
> are not on the page when the onload event is fired.
That makes life easier - register them as they are added.

Signature
Rob
> 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 ?
IE has document.elementFromPoint(x,y), but Mozilla/Firefox do not.
However, there is a quite interesting thread on simulating IE's
functionality at:
http://www.codingforums.com/showthread.php?t=21674
Csaba Gabor from Vienna