Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieving X & Y position of jQuery element

Tags:

jquery

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 ) {
        //...
    }
});
like image 682
blue-sky Avatar asked Jan 01 '26 23:01

blue-sky


1 Answers

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: }

droppable jQuery manual

$(".portletPlaceHolder").droppable({
    drop: function (evt, ui) {
        var offset = ui.offset;
        console.log(offset.left + "x" + offset.top);
    }
});
like image 72
benqus Avatar answered Jan 03 '26 15:01

benqus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!