我试图提取元素自拾起以来所经历的距离。我尝试抓住传递给offset
处理程序的position
事件的target
和stop
,但它们总是为零...
答案 0 :(得分:0)
您可以在drag
回调中查看行进方向,如下所示:
var diffX = 0;
var diffY = 0;
$('#some_div').draggable({
drag: function(e, ui) {
var start = ui.originalPosition,
end = ui.position;
diffX = end.left - start.left;
diffY = end.top - start.top;
},
stop: function(e, ui) {
console.info('Dragged: X = %o, Y = %o', diffX, diffY);
}
});