jQuery 可拖动 +可排序 - 如何拒绝排序?
我有一个可排序的视频列表和一组可拖动的视频。基本上我想确保拖入的视频不在视频的前 5 分钟内。由于视频长度各不相同,我想在下降时对此进行测试 - 将到那时的时间加起来,如果不是 5 分钟则恢复并显示错误。
我已经尝试挂钩所有可拖动和可排序的回调(包括未记录的恢复回调)来进行测试,但无论我尝试什么,dom 总是会发生变化(并且可排序调用其更新回调)...
有人有任何建议吗?
I have a sortable list of videos and a draggable set of videos. Basically I want to make sure that the videos dragged in are not in the first 5 minutes of video. As the video lengths vary I want to test this on the drop - add up the time up to then and if not 5mins revert and show an error.
I have tried hooking into all of the callbacks for draggable and sortable (including the undocumented revert callback) to do my test but whatever I try, the dom always gets changed (and sortable calls its update callback)...
Does anyone have any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过调用 draggable 的
cancel
方法来恢复拖动操作widget(该方法没有文档记录,但其名称不以下划线开头,这可以说使其使用起来“更安全”)。不过,它仅在start
事件期间起作用,因为其他事件发生得太晚而无法触发恢复动画。但是,即使拖动操作被取消, sortable 小部件仍然会注册一个放置,因此您也必须删除新添加的项目(在
stop
事件期间,因为start
事件发生得太早):您可以在 这个小提琴(第四项将始终恢复)。
更新: 正如 John Kurlak 在评论中正确指出的那样,该项目不会因为调用
draggable("cancel")
而恢复,而是因为ui.在我们的例子中,sender
为null
。扔任何东西都会导致相同的行为。唉,我尝试的所有其他组合都会导致项目在没有发生动画的情况下被恢复,所以也许我们最好的选择是避免访问 ui.sender ,而是编写如下内容:
未捕获的异常仍然会发生不过,出现在控制台中。
You can revert the drag operation by calling the
cancel
method of the draggable widget (that method is undocumented, but its name does not start with an underscore, which arguably makes it "safer" to use reliably). It only works during thestart
event, though, as other events occur too late to trigger the revert animation.However, the sortable widget will still register a drop even if the drag operation is canceled, so you also have to remove the newly-added item (during the
stop
event, as thestart
event occurs too early):You can see the results in this fiddle (the fourth item will always revert).
Update: As John Kurlak rightfully points out in the comments, the item does not revert because of the call to
draggable("cancel")
, but becauseui.sender
isnull
in our case. Throwing anything results in the same behaviour.Alas, all the other combinations I tried result in the item being reverted without the animation taking place, so maybe our best bet is to avoid accessing
ui.sender
and instead write something like:The uncaught exception will still appear in the console, though.
我找到了一种不同的方法。如果您不介意它的动画不飘回原来的位置,您可以随时使用它,
我使用它是因为无论哪种方式我都需要放置事件。
I found a different way. If you dont mind not having the animation of it floating back to it's original place you can always use this
i used this because i needed the drop event either way.