我只需要在一个下降区域中使用1个块,然后根据需要进行切换.为什么我可以禁用,但无法启用可放置功能?
> $(this).droppable(“option”,“disabled”,false); – 不起作用
> $(this).droppable(“enable”); – 不起作用
> Enable a droppable after it has being disable – 不起作用
这是我的代码:
$('.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"); },});
jsfiddle http://jsfiddle.net/4ABCN/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",ui) { ui.draggable.appendTo($(this)).removeAttr('style'); } }); } $('.my_block').droppable({ greedy: true,tolerance: 'touch',drop: function(event,ui) { ui.draggable.draggable('option',true); } }); });