0

我试图提取一个元素自从我拿起它以来已经走过的距离。我试图抓住传递给处理程序的事件的offset和,但它们总是为零......positiontargetstop

4

1 回答 1

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);
    }
});
于 2013-04-02T01:52:52.957 回答