开发者

Way to get amount of colliding elements?

开发者 https://www.devze.com 2022-12-24 16:00 出处:网络
Is there a (simple开发者_运维百科) way to return the amount of elements colliding with a single element? Perhaps with jQuery?The HTML DOM doesn\'t give us a clean way of finding all elements colliding

Is there a (simple开发者_运维百科) way to return the amount of elements colliding with a single element? Perhaps with jQuery?


The HTML DOM doesn't give us a clean way of finding all elements colliding (or overlapping) with a given element.

The only real way to do it is to check x/y positioning and height/width of each element to calculate collisions geometrically. It's obviously slow if you are checking all elements on a decent sized page.

There are plugins to make this easier to manage. gameQuery has a collision function that encapsulates all the logic for you. I'm sure there are other plugins as well.


I think there are two ways to interpret your question:

  1. Colliding elements means number of elements that are children of an another element.

  2. Colliding means elements which by appearance on the screen overlap each other.

First interpretation seems to conclude to a faster resolution but the second might require some geometry stuffed in it.

0

精彩评论

暂无评论...
验证码 换一张
取 消