如何跨div拖动 [英] How to make a draggable across divs

查看:120
本文介绍了如何跨div拖动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使元素在两个div之间可拖动?这似乎是可拖动对象应做的事情.但是我无法使用已有的代码.在这个jsfiddle中,我有两个具有可拖动元素的div.我想让一个元素从第一个div转到第二个div.该功能必须存在于许多网站上.

How do I make elements draggable between two divs? This seems to be something that draggables should do. But I haven't been able with the code I have. In this jsfiddle I have two divs with draggable elements. I want to get one element to go from the first div to the second div. That functionality must exist on many web sites.

这是带有代码的jsfiddle.

Here is the jsfiddle with the code.

http://jsfiddle.net/gkvgn/9/

我之前曾问过,以为有人会知道如何使用该功能.如果我的代码使用不正确,那么如何定义元素和可拖动的包含选项才能具有该功能.

I have asked before and thought that someone would know how to have that functionality. If the code I have isn't the right way, how do I define an element and the draggable containment option to be able to have that functionality.

推荐答案

终于找到了问题所在.为容器div指定overflow: hidden;会将可拖动区域限制为仅容器.如果我从样式中删除该规范.元素可在div上拖动.这是修复的小提琴.

Finally found the problem. Specifying overflow: hidden; for the container div restricts the draggable area to the container only. If I remove that specification from the styles. The elements are draggable across the divs. Here is the fiddle with the fix.

http://jsfiddle.net/gkvgn/10/

这篇关于如何跨div拖动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆