jQuery UI Collision: detecta divs que NO están colisionados

I'm very new to JavaScript so forgive me if this question is naive/obvious. I'm using jQuery UI drag and drop (and the jQuery Collision Detection library from this site: http://eruciform.com/static//jquerycollision/jquery-collision-drag-collision-example.html). Although I have no problems detecting which divs are colliding with each other (and doing things to said divs with ($(this).collisions(".collisionclass")).each(function() ...)), I haven't been able to find this list of divs that have NOT collided with each other or the target collider, at least not an elegant solution (and the reason is I wanted to do other actions on those remaining, uncollided divs).

Does anyone know of an elegant way to find which divs have not collided without resorting to brute force (e.g., add all such divs to a collection and every time there is a collision event check which ones from original collection are not in the resulting collision collection)? The example source code via the link above seems to simply add and remove dynamic div overlays on portions of original divs that are collided, but that doesn't tell me how to detect not-collided divs...

preguntado el 26 de agosto de 12 a las 16:08

1 Respuestas

Puedes usar jquery no método.

var not_collided = $(".item").not(".collisionclass")

Technically this will check all the items if they have the "collisionclass" class, however it is still efficient until you get to huge numbers of items.

Respondido 27 ago 12, 20:08

Thanks, Nal -- however, I'm not sure how this would work...here's my (limited) understanding of the situation: 1. Whenever a div start to get dragged, is dragging, or stopped dragging, a "handleCollision" function (that I write) is called, because I bound that function to those drag events. 2. The handleCollision function uses the jQuery Collision Library to look at all the divs and returns a collection of divs that have collided with each other. It doesn't assign any ".class" to those divs. 3. Therefore, not sure how using class filter could do this... - Uzumaki Naruto

Pass the collection of divs to the .not() method. It can take more than just a class selector. - herradura

Genius! Thanks a ton, Nal! You saved me probably a week of trial-and-error. :) - Uzumaki Naruto

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.