Jquery draggable echo返回丢弃的div类id

时间:2013-08-15 01:09:04

标签: jquery jquery-ui-draggable

我正在试图回应我放弃可拖动的粗鲁的div id。 关于如何跟踪div下降位置的任何线索。 我从jquery读了.position但是没弄明白。

这是我的小提琴。

    $('.drop').droppable({
    tolerance: 'intersect',
    drop: function(event, ui) {
        var drop_p = $(this).offset();
        var drag_p = ui.draggable.offset();
        var left_end = drop_p.left - drag_p.left + 1;
        var top_end = drop_p.top - drag_p.top + 1;

        ui.draggable.animate({
            top: '+=' + top_end,
            left: '+=' + left_end
        });
    }

});

$('.boxArt').draggable({
    revert: 'invalid',
    scroll: false,
    stack: ".boxArt"
});

Fiddle example

1 个答案:

答案 0 :(得分:1)

尝试

$('.drop').droppable({
    tolerance: 'intersect',
    drop: function(event, ui) {
        console.log(this.id)// this.id will give the `.drop` id to which the element was dropped
        var drop_p = $(this).offset();
        var drag_p = ui.draggable.offset();
        var left_end = drop_p.left - drag_p.left + 1;
        var top_end = drop_p.top - drag_p.top + 1;

        ui.draggable.animate({
            top: '+=' + top_end,
            left: '+=' + left_end
        });
    }

});

演示:Fiddle