通过绝对坐标定位DOM元素 [英] Locating DOM element by absolute coordinates
问题描述
您可以查看 document.elementFromPoint
虽然我不知道哪些浏览器支持它。
Firefox和Chrome。 它也在MSDN 中,但是我不太熟悉这个文档,所以我不知道它包含哪个IE版本。
更新:
要找到所有在这个位置上的元素,您可以假设父项的所有元素都在此位置。当然这并不适用于绝对定位的元素。
elementFromPoint
只会给你最前面的元素。要真正找到其他人,您必须将前面的元素的显示
设置为 none
,然后运行该函数再次。但用户可能会注意到这一点。你必须尝试。
Is there a simple way to locate all DOM elements that "cover" (that is, have within its boundaries) a pixel with X/Y coordinate pair?
You can have a look at document.elementFromPoint
though I don't know which browsers support it.
Firefox and Chrome do. It is also in the MSDN, but I am not so familiar with this documentation so I don't know in which IE version it is included.
Update:
To find all elements that are somehow at this position, you could make the assumption that also all elements of the parent are at this position. Of course this does not work with absolute positioned elements.
elementFromPoint
will only give you the most front element. To really find the others you would have to set the display
of the front most element to none
and then run the function again. But the user would probably notice this. You'd have to try.
这篇关于通过绝对坐标定位DOM元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!