我只需要在一个丢弃区域中使用1个块,然后根据需要进行切换。为什么我可以禁用,但无法启用可放置功能?
$(this).droppable("option", "disabled", false);
- 无效$(this).droppable("enable");
- 无效这是我的代码:
$('.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/
如何通过一个按钮将所有红色块恢复到主要位置?
答案 0 :(得分: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);
}
});
});