Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Please recommend a JQuery plugin that handles collision detection for draggable elements [closed]

We're using the Draggable JQuery UI plugin and need to disallow overlapping among our elements. We could write some collision detection ourselves but would prefer to use a tested package. Any suggestions?

like image 868
Jim Avatar asked Apr 21 '09 17:04

Jim


3 Answers

You can try jquery-collision plus jquery-ui-draggable-collision. Full disclosure: I just wrote and released these on sourceforge.

The first allows this:

var hit_list = $("#collider").collision(".obstacle");

which is the list of all ".obstacle" that overlap "#collider".

The second allows:

$("#collider").draggable( { obstacle: ".obstacle" } );

Which gives you (among other things), a "collision" event to bind to:

$("#collider").bind( "collision", function(event,ui){...} );

And you can even set:

$("#collider").draggable( { obstacle: ".obstacle", preventCollision: true } );

to prevent "#collider" from ever overlapping any ".obstacle" while dragging.

like image 86
eruciform Avatar answered Nov 02 '22 02:11

eruciform


Quick search of jQuery plugins turns up:

Collidable Draggables

Looks like it's still early, but might be worth checking out.

like image 3
Justin Niessner Avatar answered Nov 02 '22 02:11

Justin Niessner


I know this question is quite old, but maybe you will find this useful: our Collision Check Plugin for jQuery.

The description is in German, but it should be self-explanatory. You can either use two single elements or even sets of elements and will get back a set of all colliding elements.

like image 2
48design Avatar answered Nov 02 '22 01:11

48design