I'm creating a management application with some element on the page. Those element can be dragged around. but in the page you have 2 seperate places where it could be dragged.
So is there a way you can set more then one class in the containment option of the jQuery draggeble?
Thanks
set the ui containment options like following:
Per
containment
:Via https://api.jqueryui.com/draggable/#option-containment - @Vaindil mentioned this
The following is a "creative" answer regarding 'multiple containment selectors' not being directly supported by jQuery UI
sortable
. This is an "idea" which may help; in practice it did for my app:You could set
containment
using Selector or Element (see above) mode with a higher-level parent element; meaning not just the actual 'parent' but maybe something a few DOM elements higher. (If you're usingsortable
, you can connect the two.) Then use thedraggable
methodover
to determine if you're on a dropzone.You can also instantiate
droppable
on each dropzone. Here's some code that can help you determine what element you're over --- whereas this is highlighting all dropzone targets with a light-yellow bg class ('highlight') and the specific dropzone hovered with a bright-yellow bg class ('current-target'). Maybe you can use something like this to show the user where they're allowed to drop.Thus related to your
containment
question, depending on where the mouse/drag is (what it is over) you can alter the UI or thedraggable
optionaxis
(etc) on-the-fly. Try some creative solutions like this; I hope it helps!