jQuery拖放到滚动div - 删除元素不滚动

时间:2013-11-28 08:27:22

标签: jquery jquery-ui jquery-draggable

我有一个包含多个div的滚动div作为可拖动div的目标插槽。此插槽容器需要水平滚动才能看到所有目标插槽。

现在,当可拖动元素被拖动到正确的插槽中,并且插槽容器被滚动时,删除的元素不会在div中滚动。有没有办法让丢弃的div在插槽容器内滚动?

$('.draggable').draggable({
    stack: '#drag_container div',
    revert: true
});

$('.drop_target').droppable({
    accept: '#drag_container div',
    drop: handleDrop
});

function handleDrop(event, ui) { 
    var slot_number = $(this).data('number');
    var draggable_number = ui.draggable.data('number');

    if (slot_number == draggable_number) {
        ui.draggable.css('cursor', 'pointer');   
        ui.draggable.draggable('disable');

        $(this).droppable('disable');
        ui.draggable.position({ of: $(this), my: 'left top', at: 'left top'});
        ui.draggable.draggable('option', 'revert', false);
    }
}

请参阅http://jsfiddle.net/uZ8kN/7/

小提琴

2 个答案:

答案 0 :(得分:2)

见:

jsFiddle:http://jsfiddle.net/Khursheed_Ali/uZ8kN/8/

取代:

ui.draggable.position({ of: $(this), my: 'left top', at: 'left top'});

使用:

    $(this).append(ui.draggable);
    $(ui.draggable).css("position","relative");
    $(ui.draggable).css("top","0px");
    $(ui.draggable).css("left","0px"); 

答案 1 :(得分:0)

在if语句(slot_number == draggable_number)之后添加:

ui.draggable.appendTo("#drop_container");