问题
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