2015-05-19 76 views
3

我想在項目被拖動時禁用項目排序。只有在完成下降後,項目才能進行相應的排序。Jquery UI可排序 - 僅在丟棄事件時排序

 $("#sortable").sortable({ 

     tolerance: 'pointer', 
     revert: 'invalid', 
     forceHelperSize: true, 
     scroll: true, 
     forcePlaceholderSize: true, 
     placeholder: 'ui-state-highlight', 
     helper: 'clone', 
     containment: 'parent', 
     cursor: 'move',   
     distance: 5, 
     opacity: 0.3, 
    }); 
做這將是在不同的事件進行微觀佔位符位置

link:jsfiddle

+0

您的鏈接不包括在內。你能更新嗎? – mjk

+0

@mjk OP的小提琴是http://jsfiddle.net/dmUKY/353/,如果您嘗試編輯問題,您可以看到它。 @ OP:我假設你擺脫了鏈接,因爲SO的編輯抱怨你包括沒有任何代碼的鏈接;不要試圖繞過這個過濾器,只是試圖改善這個問題。我已經從小提琴中複製了JS,請編輯您認爲相關的內容 – blgt

回答

2

的一種方式。它會導致回覆問題,但可能有辦法以某種方式解決此問題。行爲可能並不完全一樣,但是再次,稍微調整一下,它可能就在那裏。總之,我的建議:

$(function() { 
    $("#sortable").sortable({ 

     tolerance: 'pointer', 
     //revert: 'invalid', 
     forceHelperSize: true, 
     scroll: true, 
     forcePlaceholderSize: true, 
     placeholder: 'ui-state-highlight', 
     helper: 'clone', 
     containment: 'window', 
     cursor: 'move', 
     distance: 5, 
     opacity: 1, 
     start: function (event, ui) { 
      place_prev = ui.placeholder.prev();//get position when selecting item 
     }, 
     change: function (event, ui) { 
      place_pos = ui.placeholder.index(); //each change you gather where the placeholder is going 
      place_prev.after(ui.placeholder);//then you place it back where it started 
     }, 
     beforeStop: function (event, ui) { 

      $('li').eq(place_pos).after(ui.item);//before stopping you place item where it was on last change event 
     }, 

    }); 

}); 

http://jsfiddle.net/2mxw14vv/3/