jQuery 将元素拖动到初始状态为隐藏的可排序列表中
我似乎无法将初始状态为隐藏(即显示:无)的元素拖动到可排序列表中。
每行的 html 如下所示:
<div class="dragbox" id="item1" >
<h2>Expression 1<span id="exp1"></span></h2>
<div class="dragbox-content" >
<ul class="dragrow1"></ul>
<ul class="dragrow2"></ul>
</div>
</div>
但是为了能够将字段放入“dragrow*”中,div“dragbox-content”必须具有“display:block”样式。这可以用主 css 样式编写,也可以硬编码到 div 本身中(例如)。
问题是,在页面加载时,您有点希望关闭所有行(或至少除了一行之外的所有行)。这意味着“显示”最初应设置为“无”。这部分很简单。一些 jQuery 可以在 read() 事件中的页面加载时更改此 css:
$('.dragbox')
.each(function(){
$(this).find('.dragbox-content').hide();
});
并且有一个名为“toggle”的 jQuery 命令,当您单击 h2 标签时,该命令会自动在块和块之间交换此 css 显示。没有任何。所以我可以显示或隐藏每一行。
所以...如果在ready()事件中显示了一行(display:block),就可以将项目拖到可排序列表中(即使您在显示和隐藏行之间切换)。
但是...如果在ready()事件中隐藏了一行(显示:无),则无法将项目拖动到可排序列表中。
有什么想法吗?真的是卡在这个上了...
I can't seem to drag an element into sortable list that has initial state as hidden (ie. display:none).
Each row's html looks like this:
<div class="dragbox" id="item1" >
<h2>Expression 1<span id="exp1"></span></h2>
<div class="dragbox-content" >
<ul class="dragrow1"></ul>
<ul class="dragrow2"></ul>
</div>
</div>
But in order for a field to be able to be dropped into a 'dragrow*', the div 'dragbox-content' has to have a style of 'display:block'. This can either be written in the main css style, or hard-coded into the div itself (eg. )
The trouble is that upon page load you kinda want all rows closed (or at least all but one). This means that 'display' should be set to 'none' initially.This part is easy. Some jQuery can change this css upon page load inside the ready() event:
$('.dragbox')
.each(function(){
$(this).find('.dragbox-content').hide();
});
And there is a jQuery command called 'toggle' which when you click the h2 tag automatically swaps this css display between block & none. So I can show or hide each row.
So... if a row is shown (display:block) within the ready() event, it is possible to drag items into the sortable list (even if you toggle between showing and hiding the row).
BUT... if a row is hidden (display:none) within the ready() event, it is impossible to drag items into the sortable list.
Any ideas? Really stuck on this one...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这可能为时已晚,但这是解决方案(也许它可以帮助其他人)。诀窍是您需要刷新可排序。
This maybe too late, but here is the solution (maybe it can help someone else). The trick is that you need to refresh the sortable.
您可以使用 connectToSortable 选项
示例
http://docs.jquery.com/UI/Draggable#option-connectToSortable
You can use the connectToSortable option
Example
http://docs.jquery.com/UI/Draggable#option-connectToSortable
不完全确定这在您的约束范围内是否是可接受的解决方案,但您必须显示要拖动到它们的元素,因此我建议在拖动开始时取消隐藏元素。这样,直到真正需要时,它们才会可见。
你可以这样做:
Not entirely sure whether this is an acceptable solution within your constraints, but you will have to show the elements to drag to them, so I would suggest unhiding the elements when the drag starts. That way they wont be visible until they really need to.
You could do something like this: