这是
实验性技术
检查
浏览器兼容性表格
要小心谨慎在生产中使用这之前。
elementsFromPoint()
方法在
DocumentOrShadowRoot
interface returns an array of all elements at the specified coordinates (relative to the viewport).
It operates in a similar way to the
elementFromPoint()
方法。
const elements = document.elementsFromPoint(x, y);
x
The horizontal coordinate of a point.
y
The vertical coordinate of a point.
An array of
element
对象。
<div> <p>Some text</p> </div> <p>Elements at point 30, 20:</p> <div id="output"></div>
let output = document.getElementById("output");
if (document.elementsFromPoint) {
let elements = document.elementsFromPoint(30, 20);
for (var i = 0; i < elements.length; i++) {
output.textContent += elements[i].localName;
if (i < elements.length - 1) {
output.textContent += " < ";
}
}
} else {
output.innerHTML = "<span style=\"color: red;\">" +
"Browser does not support <code>document.elementsFromPoint()</code>" +
"</span>";
}
| 规范 | 状态 |
|---|---|
|
Shadow DOM
The definition of 'elementsFromPoint()' in that specification. |
过时 |
|
CSSOM (CSS 对象模型) 视图模块
The definition of 'elementsFromPoint()' in that specification. |
工作草案 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
elementsFromPoint
|
Chrome
53
|
Edge
12
Alternate Name
|
Firefox 63 |
IE
10
Alternate Name
|
Opera 40 | Safari 12 |
WebView Android
53
|
Chrome Android
53
|
Firefox Android 63 | Opera Android 41 | Safari iOS 12 |
Samsung Internet Android
6.0
|
完整支持
实验。期望将来行为有所改变。
见实现注意事项。
使用非标名称。
DocumentOrShadowRoot
AbortController
AbortSignal
AbstractRange
Attr
ByteString
CDATASection
CSSPrimitiveValue
CSSValue
CSSValueList
CharacterData
ChildNode
注释
CustomEvent
DOMConfiguration
DOMError
DOMErrorHandler
DOMException
DOMImplementation
DOMImplementationList
DOMImplementationRegistry
DOMImplementationSource
DOMLocator
DOMObject
DOMParser
DOMPoint
DOMPointInit
DOMPointReadOnly
DOMRect
DOMString
DOMTimeStamp
DOMTokenList
DOMUserData
Document
DocumentFragment
DocumentType
元素
ElementTraversal
Entity
EntityReference
事件
EventTarget
HTMLCollection
MutationObserver
节点
NodeFilter
NodeIterator
NodeList
NonDocumentTypeChildNode
ProcessingInstruction
PromiseResolver
范围
StaticRange
文本
TextDecoder
TextEncoder
TimeRanges
TreeWalker
TypeInfo
USVString
UserDataHandler
XMLDocument