jQuery UI:可放置的背景?
我正在尝试创建一个垃圾桶,在您将一些物品放在那里之后,您可以简单地打开它,然后将任何已废弃的物品拖到垃圾桶外。
我设置的方式是,我的网络应用程序有一个垃圾桶图标,我可以在其中放置项目,然后单击垃圾桶会打开一个包含已废弃项目的框,并在黑色透明背景中淡出,遮盖其他所有内容,因此您只需关注垃圾桶盒子。
代码本质上是
<div id="background"></div>
<div id="trashcanContainer">
<ul id="items">
<li>item1</li>
<li>item2</li>
</ul>
</div>
背景 CSS 设置为固定位置和 100% 宽度和高度,并将其设置为可放置。问题是,当我从垃圾桶中拖动某些东西并将其放在背景上时,即使我将其放在垃圾桶顶部,它也会被删除。基本上,即使我定义了高于背景的 z-index,jQuery 也无法理解trashcanContainer div 位于背景div 的顶部(因此不是可放置的一部分)。
我有什么办法可以让这项工作成功吗?
I'm trying create a trashcan where after you've put some items there, you could simply open it and drag any trashed item out of it by dropping it outside the trashcan.
The way I've set this, is my web app has a trashcan icon where I drop the items and clicking the trashcan opens a box with the trashed items and fades in a black transparent background that obscures everything else so you just focus on the trashcan box.
The code is essentially
<div id="background"></div>
<div id="trashcanContainer">
<ul id="items">
<li>item1</li>
<li>item2</li>
</ul>
</div>
The background CSS is set to fixed position and 100% width and height and it is set as a droppable. The problem is that when I drag something from the trashcan and drop it on the background, it gets removed even if I drop it on top of the trashcan. Basically jQuery somehow doesn't understand that the trashcanContainer div is on top of the background div (and thus not part of the droppable) even if I define a z-index higher than the background.
Is there any way I can make this work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保
#trashcanContainer
使用position:absolute
或position:fixed
绝对定位,否则z-index
将没有影响。Make sure
#trashcanContainer
is absolutely positioned with eitherposition: absolute
orposition: fixed
, otherwisez-index
will have no effect.