简体   繁体   English

在我的情况下如何禁用拖动功能?

[英]How to disable dragging feature in my case?

I want to stop the dragging feature inside a draggable method. 我想停止draggable方法中的dragging功能。

$('#dragitem').draggable({
            scroll : false,
            drag: function(event, ui){
                 //a if statement
                 if(….){
                    //I want to stop the dragging here.                       
                 }
            }
 });

Is there a way to stop the dragging inside the drag function? 有没有办法停止dragging拖动功能里面? Thanks for the help! 谢谢您的帮助!

尝试:

$("#dragitem").draggable({ disabled: true });

Try this: 尝试这个:

$('#dragitem').draggable({
      scroll : false,
      drag: function(event, ui){
           //a if statement
           if(….){
                //I want to stop the dragging here.
                event.preventDefault();                      
           }
      }
 });

I've been in this situation before and I've triggered mouseup event here for lack of a better solution: 我以前曾遇到这种情况,但由于缺少更好的解决方案而在这里触发了mouseup事件:

drag: function(event, ui){
    if(true) {
        // stop dragging
        $(document).trigger('mouseup');                  
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM