通过绝对坐标定位DOM元素 [英] Locating DOM element by absolute coordinates

查看:113
本文介绍了通过绝对坐标定位DOM元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决方案

您可以查看 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆