JQuery 拖动到父级之外
我正在使用 JQuery 的draggable();使 li 元素可拖动。唯一的问题是当元素被拖到其父元素之外时,它不会显示。也就是说,它不会离开其父 div 的范围。一个例子在这里: https://i.sstatic.net/jo6tC.png - 就像如果其他所有内容的 z-index 具有更高的优先级(并且该元素滑到所有内容下方)。
代码如下:
$('.photoList li').draggable({
distance: 20,
snap: theVoteBar,
revert: true,
containment: 'document'
});
li 元素放置在 DIV 中,如下所示:
<div class="coda-slider preload" id="coda-slider-1">
<div class="panel">
<div class="panel-wrapper">
<h2 class="title" style="display:none;">Page 1</h2>
<ul class="photoList">
<li>
<img class="ui-widget-content" src="photos/1.jpg" style="width:100px;height:100px;" />
</li>
</ul>
</div>
</div>
我确信问题是它不会离开其父容器,但我不知道该怎么做才能将其取出。
任何指导或帮助将不胜感激!
I'm using JQuery's draggable(); to make li elements draggable. The only problem is when the element is dragged outside its parent, it doesn't show up. That is, it doesn't leave the confines of its parent div. An example is here: https://i.sstatic.net/jo6tC.png - it's as if the z-index for everything else has greater priority (and the element slides under everything).
Here's the code:
$('.photoList li').draggable({
distance: 20,
snap: theVoteBar,
revert: true,
containment: 'document'
});
And the li elements are placed in DIVs like this:
<div class="coda-slider preload" id="coda-slider-1">
<div class="panel">
<div class="panel-wrapper">
<h2 class="title" style="display:none;">Page 1</h2>
<ul class="photoList">
<li>
<img class="ui-widget-content" src="photos/1.jpg" style="width:100px;height:100px;" />
</li>
</ul>
</div>
</div>
I'm positive the problem is it won't leave its parent container, but I'm not sure what to do to get it out.
Any direction or help would be appreciated GREATLY!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我带着完全相同的问题登陆此页面,布伦丹的回答让我很接近。设置
appendTo
选项没有帮助,但我可以通过将overflow:visible
添加到可拖动元素的父级来解决我的问题。事实证明,我是从链条上游的某个地方草率地继承了隐藏的东西。旁注,看起来这是可行的,因为 jQuery UI 通过动态设置相对于父级的定位来移动可拖动元素 - 这对我来说是新的英特尔!
I landed on this page with the exact same problem, and Brendan's answer got me close. Setting the
appendTo
option didn't help, but I was able to resolve my issue by addingoverflow: visible
to the parent of my draggable element. Turns out I was sloppily inheriting hidden from somewhere up the chain.Side note, it looks like this works because jQuery UI moves the draggable element by dynamically setting positioning relative to the parent - this was new intel for me!
我也遇到了同样的问题。
您可以使用此选项
包含:$('#divmain')
helper: 'clone'
分别用于
- 定义下降动作的限制区域
- for 显示可见的拖动对象也在 div 父级之外但在 #divmain
示例
jquery 代码内:
我希望这对某人有帮助。
I had also the same problem.
You can use this option
containment: $('#divmain')
helper: 'clone'
respectively for
- define limit area for dropping action
- for shows visible dragged object also outside div parent but inside #divmain
example
jquery code:
I hope this help someone.
看起来上面的一些组合对我来说是这样的。
设置
appendTo: 'body'
和helper: 'clone'
。这样,一个新的 DOM 对象将被创建为主体的子对象,该对象在任何地方都可见。这样您就可以将其拖放到您喜欢的任何地方。
Looks like a combination of some of the above did it for me.
Set
appendTo: 'body'
andhelper: 'clone'
.This way a new DOM-Object will be created as child of the body which will be visible everywhere. This way you can drag (and drop) it everywhere you like.
这看起来像是一个 CSS 问题。尝试关闭还原,以便当您将其拖动到半可见的位置时它保持原状。然后在 Firebug 中使用 z-index 等,看看是否可以显示它。这可能是父 ul 或 div 之一具有“溢出:隐藏”的 CSS 问题。
This looks like a css issue. Try turning off the revert so it stays put when you drag it to where it is half visible. Then play with the z-index etc in Firebug and see if you can get it showing. It might be a css issue with one of the parent ul or div's with 'overflow: hidden'.
我遇到了类似的问题,并通过设置选项解决了它:
唯一的副作用是,如果您根据其父容器将样式应用于该项目,这些样式将不会出现在助手上。
I had a similar issue and resolved it by setting the option:
The only side effect to this is if you have styles applied to the item based on it's parent container, those styles won't be present on the helper.