jQuery 可拖动,当拖放到父 div 之外时发生事件
我有一个照片列表,并且添加了可拖动的内容,但是当照片被拖动到父 div 之外时,我想更改它的类,这样它表明如果您删除它,它将被删除,然后当用户放下它,我希望它触发一个功能。 (仅当它位于父 div 之外时)
<ul class="photos">
<li><img src=""/></li>
<li><img src=""/></li>
</ul>
因此,当将 li 拖到 .photos 之外时,它会触发添加类,然后如果它被拖放到它之外,则会触发事件以将其删除。
I have a list of photos, and I have draggable added to them, however when the photo is dragged outside of the parent div, I want to change it's class so it indicates that if you drop it, it will be removed, and then when the user drops it, I want it to fire a function. (only if it is outside of the parent div)
<ul class="photos">
<li><img src=""/></li>
<li><img src=""/></li>
</ul>
so when an li is dragged outside of .photos, it fires to add class, and then if it's dropped outside of it, then it fires and event to remove it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您提到的父
div
是可放置的,您可以将事件处理程序绑定到dropout
事件:只要将接受的可拖动对象拖到可放置对象的容差区域之外,就会触发该事件。
更新(参见注释)
您可以为
revert
选项提供回调函数。该函数可以采用一个参数,该参数要么包含可拖动对象被放置在其上的可放置对象,要么包含false
(如果它被放置在无效的地方):这是一个 工作示例。
Assuming the parent
div
you mention is a droppable, you can bind an event handler to thedropout
event:The event will fire any time an accepted draggable is dragged outside the tolerance area of the droppable.
Update (see comments)
You can supply a callback function to the
revert
option. The function can take one argument which either contains the droppable on which the draggable was dropped, orfalse
(if it was dropped somewhere invalid):Here's a working example.