jQuery droppable out 事件无法触发?
$(".LWdrop").droppable({
accept: ".LW",
drop: function(event, ui){
ui.draggable.addClass("LWactive");
$(this).droppable('option', 'accept','');
$(this).css("background-color", "#444444");
},
out: function(event, ui){
$(this).droppable('option', 'accept', '.LW');
ui.draggable.removeClass("LWactive");
},
activate: function(event, ui){
$(this).css("background-color", "blue");
},
deactivate: function(event, ui){
$(this).css("background-color", "#444444");
}
});
请忽略激活/停用时丑陋的背景颜色变化,这仅用于测试。我遇到了一个问题,即“out”没有被触发。这是否与可拖动对象设置为“恢复:无效”有关?即使删除它,我也无法从 out 事件中获取任何内容来执行......甚至是一个简单的警报框。有什么建议吗?
$(".LWdrop").droppable({
accept: ".LW",
drop: function(event, ui){
ui.draggable.addClass("LWactive");
$(this).droppable('option', 'accept','');
$(this).css("background-color", "#444444");
},
out: function(event, ui){
$(this).droppable('option', 'accept', '.LW');
ui.draggable.removeClass("LWactive");
},
activate: function(event, ui){
$(this).css("background-color", "blue");
},
deactivate: function(event, ui){
$(this).css("background-color", "#444444");
}
});
Please ignore the ugly background-color changes on activate/deactivate, that's only for testing. I'm having a problem where "out" isn't being triggered. Could this have to do with the fact that the draggables are set to "revert: invalid"? Even removing that, I fail to get anything from the out event to execute...even a simple alert box. Any tips?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当您将
draggable
悬停在droppable
上然后将其移开时,out 事件就会被触发。不幸的是,当您将draggable
拖走时,情况并非如此。The event out is triggerd when you hover a
draggable
over adroppable
and then move it away. Unfortunately not when you drag adraggable
away.当我试图让助手在拖动到可放置对象上时在视觉上发生变化(通过切换类)时,我遇到了类似的问题。和你一样,我发现 out 事件没有在我预期的时候触发。
通过一些试验和错误,我通过在结束事件上添加类并在停用事件上删除它来解决了问题。
I ran into a similar issue when trying to make the helper to change visually (by toggling a class) when dragged over a droppable. Like you, I found the out event didn't fire when I was expecting it to.
Through some trial and error, I solved the problem by adding the class on the over event, and removing it on the deactivate event.
这对某人可能有帮助。
This can be helpful for someone.