获取指定位置的元素 - JavaScript [英] Get element at specified position - JavaScript

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

问题描述

使用Javascript如何识别给定位置的元素?基本上,我希望编写一个函数,该函数接受两个输入参数(x 和 y 坐标)并返回屏幕上由参数表示的位置处的 html 元素.

Using Javascript how can I identify the element at a given position? Basically I'm looking to write a function that takes two input parameters (the x and y coordinates) and returns the html element at the position on the screen represented by the parameters.

推荐答案

document.elementFromPoint(x, y)
document.elementsFromPoint(x, y)

https://drafts.c​​sswg.org/cssom-view/#dom-document-elementfrompoint

https://developer.mozilla.org/en-US/docs/Web/API/Document/elementFromPointhttps://developer.mozilla.org/en-US/docs/Web/API/Document/elementsFromPoint

这篇关于获取指定位置的元素 - JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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