JQuery draggable - allow containment to multiple containers?

ε祈祈猫儿з 提交于 2019-12-08 11:20:54

问题


I'd like to allow users to drag an element from one container to another while still being constrained from being able to drag the element outside of either of those two containers. I have everything working perfectly except the part where they can drag to another container.

View code and result on JSFiddle.net

I thought this post seemed like the answer but it doesn't appear to work for me.


回答1:


I added a jQuery UI droppable to your fiddle. With a little bit of tweaking I'm sure you'd be able to get this exactly how you want it.

http://jsfiddle.net/U2nKh/20/




回答2:


just add these lines inside your draggable function like this:

$("#drop").draggable({revert: 'invalid',
            start: function(){
                currentParent = $(this).parent().attr('id');
            }});


来源:https://stackoverflow.com/questions/7515569/jquery-draggable-allow-containment-to-multiple-containers

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