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) . Something like:
假设我有像top:995,left:216这样的坐标。现在我想得到处于这个位置的DOM中的元素(或者是最接近这个元素的特定类的元素)。就像是:
var element = coordinates().closest('this class');
How to achieve this is javascript (jquery or angularjs solution would also work).
如何实现这一点是javascript(jquery或angularjs解决方案也可以)。
Thanks
谢谢
1 个解决方案
#1
4
Use
Document.elementFromPoint()
使用Document.elementFromPoint()
The elementFromPoint()
method of the Document interface returns the topmost element
at the specified coordinates
.
Document接口的elementFromPoint()方法返回指定坐标处的最顶层元素。
var element = document.elementFromPoint(x, y);
#1
4
Use
Document.elementFromPoint()
使用Document.elementFromPoint()
The elementFromPoint()
method of the Document interface returns the topmost element
at the specified coordinates
.
Document接口的elementFromPoint()方法返回指定坐标处的最顶层元素。
var element = document.elementFromPoint(x, y);