getElement的位置? [英] getElement by position?

查看:91
本文介绍了getElement的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理SVG脚本

有getElementById或getElementsByTagName

there are getElementById or getElementsByTagName

但我找不到任何按位置获取元素的方法

but I can't find any method to get elements by position

,例如获取位置为x = 10,y = 10的元素。

such as get the elements whose position is x=10,y=10.

有什么方法可以达到这个目的吗?

is there any way I can achieve this?

推荐答案

var yourElement = document.elementFromPoint(10, 10);

这是一个有效的工作示例,用于更改指定点处元素的背景颜色。

Here's a working example that changes the background colour of the element at the specified point.

请注意,如果指定的点位于文档的可见区域, elementFromPoint 将返回 null

Note that if the specified point is outside the visible area of the document, elementFromPoint will return null.

这篇关于getElement的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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