jQuery Draggable('cancel') 导致错误:this.helper 为 null
我有一个 jQuery Draggable() 滑块,我想在某个事件中取消它,但这会导致错误:“this.helper 为空”。代码很简单:
$( '#magicalscrollhandle' ).draggable( 'cancel' );
有什么想法吗?
I've got a jQuery draggable() slider that I want to cancel at a certain event, however this causes the error: 'this.helper is null'. The code is simply:
$( '#magicalscrollhandle' ).draggable( 'cancel' );
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“cancel”实际上并不是可拖动小部件上的有效方法。
我遇到的取消拖动事件的最佳方法是从
drag
事件处理程序返回false
。您可以根据您根据发生的事件设置的某些条件来执行此操作:因此您可以应用类
cancel
来停止拖动。这是一个小例子,我设置了一个计时器,导致元素在 5 秒后停止拖动: http: //jsfiddle.net/andrewwhitaker/y2yrA/1/
"cancel" isn't actually a valid method on the draggable widget.
The best way I've come across to cancel a drag event is to return
false
from thedrag
event handler. You could do this based on some condition that you set based on your event occurring:So you would apply the class
cancel
to stop the dragging.Here's a small example in which I set a timer which causes the element to stop being draggable after 5 seconds: http://jsfiddle.net/andrewwhitaker/y2yrA/1/