如何获得碰撞元素的数量?

发布于 2024-08-25 22:40:29 字数 46 浏览 3 评论 0原文

有没有一种(简单的)方法来返回与单个元素碰撞的元素数量?也许用 jQuery?

Is there a (simple) way to return the amount of elements colliding with a single element? Perhaps with jQuery?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

坐在坟头思考人生 2024-09-01 22:40:29

HTML DOM 并没有为我们提供一种干净的方法来查找与给定元素冲突(或重叠)的所有元素。

唯一真正的方法是检查每个元素的 x/y 定位和高度/宽度,以几何方式计算碰撞。如果您要检查大小合适的页面上的所有元素,这显然会很慢。

有一些插件可以使其更易于管理。 gameQuery 有一个碰撞函数,为您封装了所有逻辑。我确信还有其他插件。

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.

别忘他 2024-09-01 22:40:29

我认为有两种方法可以解释您的问题:

  1. 碰撞元素意味着作为另一个元素的子元素的元素数量。

  2. 碰撞意味着元素在屏幕上的外观相互重叠。

第一种解释似乎得出了更快的分辨率,但第二种解释可能需要填充一些几何图形。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文