【问题标题】:How to access the co-ordinates of an element as it's being dragged如何在拖动元素时访问它的坐标
【发布时间】:2025-11-26 16:15:02
【问题描述】:

如果我使用这个函数使一个元素可以使用 jQuery ui 可拖动:

$(document).ready(function() {
  $("#draggableSquare").draggable();
});

如何在元素移动时访问它的坐标?

【问题讨论】:

标签: jquery jquery-events jquery-ui-draggable


【解决方案1】:
$( "#draggable" ).draggable({
    drag: function(event,ui) {
        //relative to container: ui.position.left and ui.position.top 
        //ralative to page: ui.offset.left and ui.offset.top
    }
});

jsFiddle

【讨论】:

    最近更新 更多