Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent draggable child elements from dragging over each other?

How to prevent draggable child elements from dragging over each other in absolute position? Something like:

if( ($("#firstChild").position().left) >= ($("#secondChild").position().left) )
{
    $(this).draggable({ disabled: true });
}

but this only disables dragabble when stop dragging, the goal is to prevent from overdragging in some way...Or with Droppable???

enter image description here

Any ideas for CASE 2?

EDIT:

Also, this is maximum for child1 towards child2 , so no overlap occurs, but child1 can push child2 on right, and child2 can push child1 on left, important thing is that no overlap ocurrs!

like image 771
Davor Zubak Avatar asked Dec 10 '25 19:12

Davor Zubak


1 Answers

you can use gamequery plugin. theres a collision detection.

second thing you can do is: when you hover your element while dragging... just trigger drop ? so he will never be able to drag it inside. make something like drag position of mouse at the right of the dragged element so you are sure thats not possible to drag it inside this element.

i hope you know what i mean

example calling drop:

$('#rightbox').live('mouseenter', function(){
  $('#leftbox').droppable.option('drop');
});

something like that... havent test it but its a way to start with

like image 168
ggzone Avatar answered Dec 13 '25 08:12

ggzone



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!