get element location

D

dave.wayne

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 ?
 
R

RobG

(e-mail address removed) 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.
 
D

dave.wayne

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.
 
R

RobG

(e-mail address removed) 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top