How do I implement collision detection between a set of Div elements?
I have this example in jsfiddle I have a var as being the collision element: var $div = $('.container'); and then the collision: function test (){ $('.drag') .drag("start",function( ev, dd ){ dd.limit = $div.offset(); dd.limit.bottom = dd.limit.top + $div.outerHeight() - $( this ).outerHeight(); dd.limit.right = dd.limit.left + $div.outerWidth() - $( this ).outerWidth(); }) .drag(function( ev, dd ){ $( this ).css({ top: Math.min( dd.limit.bottom, Math.max( dd.limit.top, dd.offsetY ) ), left: Math.min( dd.limit.right, Math.max( dd.limit.left, dd.offsetX ) ) }); }); } for: <div class="container"