Reputation: 53796
I need to retrieve the X & Y position of an element once its dropped, how can I implement this ?
I think I need to use the droppable callback :
$(".portletPlaceHolder").droppable({
drop: function( event, ui ) {
//...
}
});
Upvotes: 3
Views: 12135
Reputation: 9954
Use .offset()
<script>
var p = $("p:last");
var offset = p.offset();
p.html( "left: " + offset.left + ", top: " + offset.top );
</script>
UPDATE
http://www.jquery4u.com/snippets/jquery-coordinates-element/#.T7YW7Nz9Mi0 http://www.quirksmode.org/js/dragdrop.html http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/clientX.htm
This one is Awsm Show Dynamic Coordinates of cursor movement
http://www.diffusedreality.com/content.html
Upvotes: 2
Reputation: 1139
Mate, you should read the whole page on a documentation:
All callbacks receive two arguments: The original browser event and a prepared ui object, view below for a documentation of this object (if you name your second argument 'ui'):
- ui.draggable - current draggable element, a jQuery object.
- ui.helper - current draggable helper, a jQuery object
- ui.position - current position of the draggable helper { top: , left: }
- ui.offset - current absolute position of the draggable helper { top: , left: }
$(".portletPlaceHolder").droppable({
drop: function (evt, ui) {
var offset = ui.offset;
console.log(offset.left + "x" + offset.top);
}
});
Upvotes: 5
Reputation: 1126
you could use the position()
function who retrieve the top and left position
$('yourselector').position();
Upvotes: -1