jquery可排序占位符高度问题
由于某种原因,我的可排序项目的占位符约为 10 像素。我所有可排序的物品都有不同的高度。如何更改每个占位符的高度以匹配正在移动的项目?
For some reason the placeholder for my sortable items is about 10px. All my sortable items have different heights. How can I change the height of each placeholder to match the item being moved?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我通常通过绑定一个回调来解决这个问题,该回调将占位符的高度设置为排序到
开始
事件。这是一个简单的解决方案,可让您精细控制占位符的显示方式。请参阅更新的测试用例
I usually solve this by binding a callback that sets the height of the placeholder to the height of the item being sorted to the
start
event. It's a simple solution that gives you fine-grained control over how you want your placeholder to be displayed.See updated test case
您是否尝试过设置
forcePlaceholderSize:true
属性?请阅读 jQuery UI Sortable 文档页面。Have you tried setting the
forcePlaceholderSize:true
property? Have a read on the jQuery UI Sortable documentation page.当从外部容器拖动项目时,您也可以使用“ui.helper[0].scrollHeight”来稳定结果,而不是使用“ui.item.height()”。
Instead of using "ui.item.height()" you can use "ui.helper[0].scrollHeight" to stable result when drag an item from external container too.
你的元素是
display: block
吗?内联元素可能会使占位符无法正确保持高度。例如。 这个jsFiddle似乎与您描述的问题有类似的问题。将display: block
添加到.portlet
类可以修复此问题。Are your elements
display: block
? Inline elements might make the placeholder not keep the height correctly. Eg. this jsFiddle seems to have a similar problem to the one you described. Addingdisplay: block
to the.portlet
class fixes it.就我而言,我找到了类似于 JP Hellemons 的解决方案,其中我强制占位符的高度(带有!重要)自定义,并设置背景可见性以查看我自己的更改(您也可以按照您想要的方式设置占位符的样式)。
这也适用于
display: inline-block;
In my case I found solution similar to JP Hellemons, in which I'm forcing height of placeholder (with !important) to custom and also setting visibility with background to see changes for myself (also you can style this way your placeholder anyhow you want).
This works also with
display: inline-block;
您可以为占位符设置样式作为可排序的选项。
并给这种风格一个高度。希望有效。
You can set a style for your placeholder as an option for your sortable.
And just give that style a height. Hope that works.