I am trying to create multiple jquery droppables next to eachother where some parts might overlap, in these cases I want the one that is on top (z-index wise) to be greedy.
I have tried setting the greedy: true
option in the droppable, but this does not seem to help. I have also tried to return false
on the drop event and used event.stopPropagation();
.
Here is a jsfiddle based on the demo page of jquery.
Is there any way to stop the drop event from propagating if there is another droppable triggering it, preferably the one that has the highest z-index?
If just want it to look the same you can set the #droppable3 to position: relative and set the child #droppable3-inner to position: absolute.
HTML:
Here is the live example
The greedy options is just for nested elements that have a droppable parent.
In your code the 2 droppable elements are siblings so the greedy option will not work:
Here is a messy workaround if you still want to use siblings instead of parents and children.
Live code example.
You need a function to check if the element is the highest visible element. Something is the highest visible when
The below function can be used to see if the current element (either in over method or drop method in the droppable setting) is in fact the highest visible element.
Use
document.elementFromPoint
to check the element directly under the cursor. If it’s not your droppable, don’t do anything. Add the following to the top of yourdrop:
handler:Disabling pointer events on the helper is necessary for
document.elementFromPoint
to ignore the thing your dragging and only checking underneath. I’ve updated your jsFiddle for a quick demonstration. Note that the highlight still affects both elements. You should be able to change that by not letting jQuery UI do the highlighting but instead write it yourself on the draggablesdrag:
event. I have, however, found this to be unusable in practice as this check (and disabling pointer events) is quite slow and may also cause flickering.If i had this issue i would use jQuery's .addclass
make a class as such so the layer stays on top no matter what.. this should fix the issue.