简体   繁体   English

如何基于坐标获取元素

[英]How to get element based on coordinates

Suppose i have coordinates like top: 995, left: 216. Now i want to get the element in the DOM which is in this position (or an element of a particular class which is closest to this element) . 假设我的坐标像top:995,left:216。现在,我想获取DOM中位于此位置的元素(或最接近此元素的特定类的元素)。 Something like: 就像是:

var element = coordinates().closest('this class');

How to achieve this is javascript (jquery or angularjs solution would also work). 如何实现此目的是使用javascript(jQuery或angularjs解决方案也可以)。

Thanks 谢谢

Use Document.elementFromPoint() 使用Document.elementFromPoint()

The elementFromPoint() method of the Document interface returns the topmost element at the specified coordinates . Document接口的elementFromPoint()方法返回指定coordinates处的最高element

var element = document.elementFromPoint(x, y);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM