2014-02-11 54 views
2

我想停止draggable方法中的dragging功能。如何在我的情況下禁用拖動功能?

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

有沒有辦法在拖動功能裏面停止dragging?謝謝您的幫助!

+0

你試過'返回false;'?嘗試將其添加到該塊。這應該結束功能。 – royhowie

+0

@Luxelin不,它不起作用。 – FlyingCat

+0

你有沒有得到它的工作呢? –

回答

0

嘗試:

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

試試這個:

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

如果這不起作用,請嘗試'e.stopPropogation();' – royhowie

+0

我認爲你的意思是'event.stopPropogation();'?據我所知,代碼中沒有定義「e」。 –

+0

爲什麼我們需要'event.stopPropogation()'?這裏沒有來自父節點的事件。只需'preventDefault()' – ducdhm

0

我已經在之前這種情況下,我已經觸發mouseup事件在這裏沒有更好的解決辦法:

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