jQuery draggable('cancel') causing error: this.helper is null

断了今生、忘了曾经 提交于 2019-12-12 17:29:37

问题


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?


回答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 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.

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/



来源:https://stackoverflow.com/questions/5006271/jquery-draggablecancel-causing-error-this-helper-is-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!