On Monday 15 January 2007 18:55, Daniel Haller wrote:
Hi there,

does anybody know if there's a way to figure out which coordinates an
element has AFTER it was dragged across the page by the user?

I user the scriptacolous Lib like this...:
new Draggable('notice',{handle:'notice_ctrl',zindex:1000});
...and I want to store the X/Y-Position of the Element 'notice' to a
Database. How do I get this values after Dragging? offsetTop/offsetLeft
does not work, this returns the X/Y-Position of the Element BEFORE it
was dragged.

Thank you for your patience,
Daniel

Hi Daniel,

offsetTop/offfsetLeft work for me in a very simple mocked-up example, coded in below (just add your own Prototype & Scriptaculous libs!)

<html>
<head>
<script type='text/javascript' src='prototype/prototype.js'></script>
<script type='text/javascript' src='scriptaculous/scriptaculous.js'></script>
</head>
<body>

<div id='el1'>I'm element 1</div>
<div id='el2'>I'm element 2</div>

<script type='text/javascript'>

var el=$("el1");
el.style.border='solid red 2px';
new Draggable(el);

var el2=$("el2");
el2.style.backgroundColor='gray';

Event.observe(
 el,'mousemove',
 function(){ el2.innerHTML=el.offsetLeft+" x "+el.offsetTop; }
);
</script>
</body>
</html>

You can drag element 1 around the screen, and element 2 should update with it's coordinates. In Firefox (and Konqueror FWIW), it responds pretty snappily, with the numbers rolling along as you move. Under IE7, it looks like it takes half a second or so for the coordinates to update themselves after the drag operation has stopped. - I don't have IE6 to hand to check if this is a new 'feature' (IE7 seems to be full of them).

In your case, the lag can probably be worked around - I assume you're not trying to talk to the database in real time, but only after the drop operation.
HTH

Dave --
----------------------
Author
Ajax in Action http://manning.com/crane
Ajax in Practice http://manning.com/crane2
Prototype & Scriptaculous Quickly http://manning.com/crane3

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on 
Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to