为什么我可以禁用,但无法启用可放置功能?

Eug*_*off 5 jquery jquery-ui droppable draggable

我只需要在一个下降区域中使用1个块,然后根据需要进行切换.为什么我可以禁用,但无法启用可放置功能?

  • $(this).droppable("option", "disabled", false); - 不起作用
  • $(this).droppable("enable"); - 不起作用
  • 禁用后启用droppable - 不起作用

这是我的代码:

$('.my_block').draggable({
    revert: "invalid",        
});

$('.free').droppable({         
    accept: ".my_block",
    drop: function(ev, ui) {             
        $(this).removeClass("free");    
        $(this).addClass("1");                
        ui.draggable.appendTo($(this)).removeAttr('style');
            $(this).droppable("disable");              
        },
        out:  function(ev, ui) {                     
            $(this).droppable("enable");    
            $(this).removeClass("1");    
            $(this).addClass("free");            
        },        
    });
Run Code Online (Sandbox Code Playgroud)

jsfiddle http://jsfiddle.net/4ABCN/2/

如何通过一个按钮将所有红色块恢复到主要位置?

Tat*_*nit 2

工作演示 删除了旧演示

新演示试试这个: http: //jsfiddle.net/7EbKS/

行为:现在,当用户移动红色框时,您可以将另一个框放在空位置,

希望它符合原因:)

代码

  $(function() {
    foo();

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

    });

    function foo() {
        $('.block').droppable({
            greedy: true,
            accept: ".my_block",
            // tolerance: "fit",
            drop: function(ev, ui) {
                ui.draggable.appendTo($(this)).removeAttr('style');
             }
        });
    }
    $('.my_block').droppable({
        greedy: true,
        tolerance: 'touch',
        drop: function(event, ui) {
            ui.draggable.draggable('option', 'revert', true);
        }
    });

});
Run Code Online (Sandbox Code Playgroud)