2015-05-26 87 views
0

我有多個可排序的列(<uls>),可以在它們之間拖動多個<li>元素。當您拖動選項時,即使完全禁用佔位符,它也會取代光標下方的其他選項。我的首選行爲是:JQueryUI可排序,無佔位符位移

  1. 光標下方沒有位移。
  2. 將項目放入<ul>時,應將其添加到列表的底部,而不是光標懸停的任何位置。

我已經試驗了forcePlaceholderSize屬性,以及試圖用高度爲0的佔位符,但既不似乎工作(前者似乎並沒有產生效果,無論它是否是真的還是假的,即使我用CSS中的!important覆蓋它,後者總是顯示一個具有某種最小高度的佔位符)。

+1

請參閱http://stackoverflow.com/questions/30322532/jquery-ui-sortable-sort-only-on-drop-event/30387678#30387678。你可能會應用相同的邏輯,除了你可以設置位置到最後一個項目的結尾。 –

回答

0

感謝來自@JulienGrégoire指着我的方向是正確的評論,我最終加入以下我排序的代碼來完成我需要的東西:

$("ul.my_sortable").sortable({ 
    ... 
    start: function (event, ui) { 
     // get placeholder position when selecting item 
     place_prev = ui.placeholder.prev(); 
     start_col = $(this); 
     target_col = $(this) 
    }, 
    change: function (event, ui) { 
     // keep track of where the placeholder moves... 
     place_pos = ui.placeholder.index(); 
     // and reset it back to its starting position so it doesn't appear to move 
     place_prev.after(ui.placeholder); 
    }, 
    beforeStop: function (event, ui) { 
     // move the choice to the correct column when you let go 
     if (!target_col.is(start_col)) { 
      target_col.append(ui.item); 
     } 
    } 
}); 

這似乎仍然有點低效雖然,不斷保姆佔位符。如果其他人能想出更好的方法,我很樂意聽到它!