由于某种原因,我的可排序项目的占位符高度约为10px。我所有的可排序项目高度都不同。如何更改每个占位符的高度以匹配移动的项目?
由于某种原因,我的可排序项目的占位符高度约为10px。我所有的可排序项目高度都不同。如何更改每个占位符的高度以匹配移动的项目?
你是否尝试设置forcePlaceholderSize:true
属性?请参考jQuery UI Sortable文档页面。
.ui-sortable-placeholder { border: 1px dotted black; visibility: visible !important; height: 50px !important; }
为 .ui-sortable-placeholder { border: 1px dotted black; visibility: visible !important; }
(因此删除高度)。所以@DarthJDG,你是正确的! - JP Hellemons与其使用“ui.item.height()”,您可以使用“ui.helper[0].scrollHeight”来稳定结果,这样当从外部容器拖动项目时也能保持结果稳定。
$( ".column" ).sortable({
connectWith: ".column",
start: function(e, ui){
ui.placeholder.height(ui.helper[0].scrollHeight);
}
});
您的元素是否具有 display: block
?行内元素可能会导致占位符无法正确保持高度。例如,这个 jsFiddle 看起来有一个与您描述的问题类似的问题。将 .portlet
类添加 display: block
可以解决该问题。
display: inline-block;
。.ui-sortable-placeholder {
background:red !important;
height: 2px !important; // this is the key, set your own height, start with small
visibility: visible !important;
margin: 0 0 -10px 0; // additionaly, you can position your placeholder,
} // in my case it was bottom -10px
您可以为可排序选项设置占位符的样式。
$( "#sortable" ).sortable({
placeholder: "ui-state-highlight"
});
只需为该样式设置一个高度。希望这能起作用。