【发布时间】:2014-01-10 22:51:53
【问题描述】:
在与这个问题斗争和斗争之后,我别无选择,只能寻求帮助!我的情况是这样的:我有许多绝对定位元素。每个元素都有自己的属性“top”和“left”。我遇到的最大问题是当我尝试对项目进行排序时。
$(".container").sortable({
containment: ".container",
cursor: 'move',
items: '.element',
helper: 'clone',
placeholder: 'new-placeholder',
forcePlaceholderSize: true,
tolerance: 'pointer',
revert: true,
scroll: false,
start: function(event, ui) {
event.stopPropagation();
$(".new-placeholder").css("left", ui.helper.position().left);
$(".new-placeholder").css("top", ui.helper.position().top);
$(".new-placeholder").css("height", ui.helper.height());
$(".new-placeholder").css("width", ui.helper.width());
},
change: function(event, ui) {
console.log("Placeholder index: " + ui.placeholder.index());
}
}).disableSelection();
这是Current Behavior,这是Expected behavior
如您所见,当拖动元素结束时,元素应该改变它们的位置。有没有更好的方法来做到这一点?我无法摆脱绝对位置,这是主要问题。我知道解决方案必须是更改、更新和停止方法,但我自己无法解决。
到目前为止,我得到的只是当项目被拖动到另一个元素上时获取占位符的新索引,但是 ¿我如何更改占位符的位置并根据该索引对其余元素进行排序?
【问题讨论】:
-
我也使用了绝对定位的元素。我永远无法让它与 sortable 一起工作。我必须为我的 sortables 创建一个新的布局管理器,以便它可以像(实际上,比)原始的绝对定位布局一样工作。
-
@greg-pettit 感谢您的回答!我仍在努力让它发挥作用。你能给我一些方法想法来实施你所说的解决方案吗?我应该摆脱可排序的吗?据我所见,可排序根本不适用于绝对位置。即使我使用相对位置,如果我使用 JQuery 设置顶部和左侧属性,排序后的结果是一团糟。非常感谢提前!!!
标签: jquery jquery-ui jquery-ui-sortable absolute