当可拖动对象不被可放置对象接受时,有办法设置一个函数吗?
例如
droppables处于启用状态,当draggable开始被拖动时,如果它们被接受,droppables将获得“activeClass”,如果它们不被接受,droppables将获得“inactiveClass”(例如)
有一个简单的方法可以做到这一点吗?
最佳答案
如果可拖动对象不被可放置对象接受,我也遇到这个问题来执行某些函数。经过大量搜索后,我发现您可以为可拖放不接受可拖放的场景提供功能。我发现可拖动选项恢复还可以具有除“真、假、有效、无效”值之外的功能。 您可以指定一个要恢复的函数,即使将可拖动对象放入可放置对象中以及未将其放置在可放置对象上时,该函数也会执行。
$("selector").draggable({
revert : function(droppableContainer) {
if(droppableContainer) {
//if drop is valid i.e. draggable is dropped on a valid droppable or droppable has accepted the draggable
}
else {
//if drop is invalid i.e. droppable has not accepted the draggable
}
return(!droppableContainer) //returns true if invalid drop i.e draggable will revert and false if the draggable has been dropped correctly and thus no revert
}
});
关于Jquery UI 可删除 "not accepted"事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19656856/