Exact top left coordinates of movable image.

M

MarkusJNZ

Hi all, I have a page which allows a user to drag and drop one or more
images on a page.

I have a function which is passed in a reference to the item being
dragged so I can do things like;

Pseudo code below:

function Drop(obj)
{
alert(document.GetByElementId(obj).style.posLeft);
}

The above seems to give the offset x coordinate from the objects
original position.

Likewise I have tried

alert(document.GetByElementId(obj).style.Left); Which gives the same
value

I have also tried capturing the x and y coordinate of the mouse when
the person releases the mouse button. The problem is that if the person
drags the image in the middle then it does not give the correct top
left of the image.

So, can anyone please tell me how I can get the top left coordinates of
the item being dragged when a person releases the mouse button?

TIA
Markus
==================================
googlenews2006markusj
 
P

Peter Michaux

RobG said:
Hi all, I have a page which allows a user to drag and drop one or more
images on a page.
[...]

So, can anyone please tell me how I can get the top left coordinates of
the item being dragged when a person releases the mouse button?

Peter-Paul Koch gives some explaination of position here:
<URL: http://www.quirksmode.org/js/findpos.html >


Try Matt Kruse's Position library:
<URL: http://www.javascripttoolbox.com/lib/objectposition/ >

I did find that these positioning algorithms didn't work properly in
IE, Firefox, Opera and Safari on Mac and Windows. They all had one
problem in at least one browser. The test cases included nested
scrolling elements and tables.

I have found that with dragdrop you can usually find ways to avoid
needing the position calculated in the complex offsetParent way. Just
inline style coordinates relative to the first ancestor with
position:relative or other simple ways. With all the browser
difficulties in element positioning I have been trying to avoid it when
possible and that has seemed like all the time lately.

Peter
 
M

MarkusJNZ

Thanks everyone!
Regards
Markus
Peter said:
RobG said:
Hi all, I have a page which allows a user to drag and drop one or more
images on a page.
[...]

So, can anyone please tell me how I can get the top left coordinates of
the item being dragged when a person releases the mouse button?

Peter-Paul Koch gives some explaination of position here:
<URL: http://www.quirksmode.org/js/findpos.html >


Try Matt Kruse's Position library:
<URL: http://www.javascripttoolbox.com/lib/objectposition/ >

I did find that these positioning algorithms didn't work properly in
IE, Firefox, Opera and Safari on Mac and Windows. They all had one
problem in at least one browser. The test cases included nested
scrolling elements and tables.

I have found that with dragdrop you can usually find ways to avoid
needing the position calculated in the complex offsetParent way. Just
inline style coordinates relative to the first ancestor with
position:relative or other simple ways. With all the browser
difficulties in element positioning I have been trying to avoid it when
possible and that has seemed like all the time lately.

Peter
 

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
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top