How can I find whether there are any elements at a certain position?

妖精的绣舞 提交于 2019-12-11 19:29:56

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/5476468/how-can-i-find-whether-there-are-any-elements-at-a-certain-position

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!