使 div 对于某些元素可拖动和可放置
我有一个带有可拖动和可放置的 div 的页面。每个 div 都包含可拖动的嵌套 div。我希望能够将嵌套的 div 从 div 1 拖放到 div 2 上,反之亦然。我尝试执行此操作的 jsfiddle 位于此链接 http://jsfiddle.net/fWhDn/
如果我将 msn.com 链接(可拖动的 div)从 div 2 移动到 div 1,它不会放入该 div 中。我必须修复什么才能获得正确的行为,即该链接成为 div 1 的一部分的位置?
I have a page with divs that are draggable and droppable. Each div contains nested divs that are also draggable. I want to be able to drag nested divs from div 1 and drop them on div 2 and also the other way around. The jsfiddle where I try to do that is at this link http://jsfiddle.net/fWhDn/
If I move the msn.com link (draggable div) from div 2 to div 1, it isn't dropped into that div. What do must I fix to get the right behavior, i.e. where that link becomes part of div 1?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要使其正常工作,您必须将可拖动的 div 附加到相应的可放置的 div 中。您可以通过 droppable init 内的 drop 事件来完成此操作。我为每个可放置的 div 设置了它,以便访问 $(this)。重置项目的 css 也很重要,因为如果不重置它,它将保留您拖动它时的位置。以下是我添加的内容:
这是更新的小提琴: http://jsfiddle.net/TpbZk/
To get this to work you have to append the draggable div to the respective droppable div. You can do this through the drop event inside the droppable init. I set it up for each droppable div in order to get access to the $(this). It's also important to reset the css of the item as if not it will carry over the position it had when you were dragging it. The following is what I added:
And here's the updated fiddle: http://jsfiddle.net/TpbZk/