jQuery draggable('cancel')导致错误:this.helper为null [英] jQuery draggable('cancel') causing error: this.helper is null

查看:55
本文介绍了jQuery draggable('cancel')导致错误:this.helper为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个jQuery draggable()滑块,我想在某个事件中取消,但这会导致错误:'this.helper为null'。代码很简单:

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' );

任何想法?

推荐答案

取消实际上不是可拖动的有效方法小部件。

"cancel" isn't actually a valid method on the draggable widget.

我遇到取消拖动事件的最佳方法是从<返回 false code>拖动事件处理程序。您可以根据您根据发生的事件设置的某些条件执行此操作:

The best way I've come across to cancel a drag event is to return false from the drag event handler. You could do this based on some condition that you set based on your event occurring:

$("#draggable").draggable({
    drag: function() {
        if ($(this).hasClass("cancel")) {
            return false;
        }
    }
});

因此,您可以将取消类应用于停止拖动。

So you would apply the class cancel to stop the dragging.

这是一个小例子,我设置了一个定时器,使得元素在5秒后停止可拖动: http://jsfiddle.net/andrewwhitaker/y2yrA/1/

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/

这篇关于jQuery draggable('cancel')导致错误:this.helper为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆