Getting the X and Y Positions of a jQuery Element

I need to get the X and Y position of an element after deleting it, how can I implement this?

I think I need to use the droppable callback:

$(".portletPlaceHolder").droppable({
    drop: function( event, ui ) {
        //...
    }
});
+3
source share
3 answers

Mate, you should read the entire page in the documentation:

All callbacks receive two arguments: the source browser event and the prepared ui object, see below for documentation of this object (if you call your second argument “ui”):

  • ui.draggable - current drag and drop item, jQuery object.
  • ui.helper - current draggable helper, jQuery object
  • ui.position - the current position of the dragging helper {top :, left:}
  • ui.offset - current absolute position of the dragging helper {top :, left:}

droppable jQuery manual

$(".portletPlaceHolder").droppable({
    drop: function (evt, ui) {
        var offset = ui.offset;
        console.log(offset.left + "x" + offset.top);
    }
});
+5

.offset()

<script>
   var p = $("p:last");
   var offset = p.offset();
   p.html( "left: " + offset.left + ", top: " + offset.top );
</script>

http://api.jquery.com/offset/

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

Awsm

http://www.diffusedreality.com/content.html

+2

you can use a function position()that extracts top and left positions

$('yourselector').position();
-1
source

All Articles