How can I find whether there are any elements at a

2019-09-02 05:00发布

I have a collection of divs with the same class at various positions on a larger div. Is there a way, using jQuery, to determine if any divs are overlapping a given position on the screen?

2条回答
Ridiculous、
2楼-- · 2019-09-02 05:25

Read the section on document.elementFromPoint(): http://www.quirksmode.org/blog/archives/2010/06/more_ie9_goodne.html

You can use this to find the "top-most" element at that location. Hide that element, then ask again. If you get another hit, then the 2 divs overlap at that position.

查看更多
▲ chillily
3楼-- · 2019-09-02 05:40

You could do this using the offset() method of JQuery, but the only way to be accurate is to get the offset of every element in the document -- not likely to perform well.

查看更多
登录 后发表回答