【发布时间】:2012-04-26 17:24:56
【问题描述】:
我只在其他几个地方看到过这个问题的几个变体,特别是 here 和 here。
基本上,我有一个跳棋棋盘,棋盘上的每个方块都是可放置的,每个棋子都是可拖动的。每个方块一次只能有一块,我正在尝试根据方块上是否有一块来切换启用/禁用方法。
这是我目前所获得的链接:http://jsbin.com/ayalaz,下面是最相关的代码。
function handleDrop(e, ui) {
var tileNumber = $(this).data('tile');
// Make the gamepiece snap into the tile
ui.draggable
.data({ // WHAT IF PIECE IS SET BACK DOWN IN SAME TILE... CHECK FOR IT!
'preRow': ui.draggable.data('curRow'),
'preCol': ui.draggable.data('curCol'),
'curRow': $(this).data('row'),
'curCol': $(this).data('col')
});
$(this).append($(ui.draggable));
ui.draggable
.position({
of: $(this),
my: 'left top',
at: 'left top'
});
$(this).droppable('disable');
//console.log("Gamepiece set down at: (" + $(this).data('row') + "," + $(this).data('col')+ ")");
}
function handleOut(e, ui) {
// HOW TO TOGGLE DROPPABLE??
$(this).droppable('enable');
}
有什么建议吗?
提前致谢! 杰里米
【问题讨论】:
标签: jquery-ui jquery-ui-draggable jquery-ui-droppable