我有多个可排序的列 ( <uls>
) 彼此相邻,其中有许多 <li>
您可以在它们之间拖动的元素。当你四处拖动一个选项时,它会取代光标下方的其他选项,即使我完全禁用占位符也是如此。我的首选行为是:
- 光标下方没有位移。
- 当元素被放入
<ul>
, 它应该附加到列表的底部而不是光标悬停的地方。
我试验过 forcePlaceholderSize 属性,也试过高度为 0 的占位符,但似乎都不起作用(前者似乎没有效果,不管它是真还是假,而后者总是显示具有某种最小高度的占位符,即使我在 CSS 中用 !important
覆盖它也是如此。
最佳答案
感谢@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);
}
}
});
不过,这似乎仍然有点低效,因为它不断地照看占位符。如果有人能想出更好的方法,我很乐意听听!
关于javascript - JQueryUI 可排序,无占位符位移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30466944/