JQuery draggable - allow containment to multiple c

2019-06-11 01:02发布

问题:

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');
            }});