jQuery只拖放外部div

时间:2012-01-06 00:18:09

标签: jquery draggable droppable

由于这个问题,我几乎有了解决方案:Draggable revert if outside this div and inside of other draggables (using both invalid and valid revert options)

我已经修改了jsfiddle中的代码http://jsfiddle.net/phoebebright/jcRN7/1/,以演示我想要做的事情,显示外部div,其中项目是可放置的,而内部div则不是,更容易演示而不是解释!

如何阻止div被丢弃在可以放置的div中的div上?

1 个答案:

答案 0 :(得分:2)

$('.drop').droppable({
    tolerance: 'fit',
});

$('.drag').draggable({
    revert: 'invalid',
    stop: function() {
        $(this).draggable('option', 'revert', 'invalid');
    }
});

$('.drag').droppable({
    greedy: true,
    tolerance: 'touch',
    drop: function(event, ui) {
        ui.draggable.draggable('option', 'revert', true);
    }
});

尝试添加此内容:

$('#nogo').droppable({
    greedy: true,
    drop: function(event,ui){
        ui.draggable.draggable('option','revert',true);
    }
});