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

时间:2014-02-11 01:24:34

标签: javascript jquery html css jquery-ui

我想在dragging方法中停止draggable功能。

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

有没有办法阻止拖动功能中的dragging?谢谢你的帮助!

3 个答案:

答案 0 :(得分:0)

尝试:

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

答案 1 :(得分:0)

试试这个:

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

答案 2 :(得分:0)

之前我一直处于这种情况,因为缺乏更好的解决方案,我在这里触发了mouseup事件:

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