How to make a draggable across divs

自闭症网瘾萝莉.ら 提交于 2019-12-02 13:18:35

问题


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.

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.


回答1:


There's a similar Stack Overflow question that was answered here: jquery ui draggable elements not 'draggable' outside of scrolling div

I implemented the above solution on my own project and it worked beautifully.

I agree that it does seem like if you set the containment to window or document, cross-div dragging should be allowed. I imagine that you'd prefer overflow to stay hidden due to the amount of content you want to keep in your divs.




回答2:


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/



来源:https://stackoverflow.com/questions/7825337/how-to-make-a-draggable-across-divs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!