Jquery draggable position - clone

我怕爱的太早我们不能终老 提交于 2019-12-04 19:12:24

You'll have to do the calculation yourself:

var
  draggableDocumentOffset = ui.helper.offset(),
  droppableDocumentOffset = $(this).offset(),
  left = draggableDocumentOffset.left - droppableDocumentOffset.left,
  top = draggableDocumentOffset.top - droppableDocumentOffset.top;

alert('Item was dropped at - Left: ' + left + ', Top: ' + top); 

It is maybe not the most beautiful solution but you can get the position of the drop in the document by:

x=event.pageX;
y=event.pageY;

And then use the coordinates of the droppble area to substract from x and y.

dx=$("#droparea").offset().left;    
dy=$("#droparea").offset().top;    
var left=x-dx;          
var top=y-dy;   

K

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!