DOM
The hasPointerCapture() method of the
Element interface checks whether the element on which it is invoked has
pointer capture for the pointer identified by the given pointer ID.
Syntax
hasPointerCapture(pointerId)
Parameters
pointerId- : The PointerEvent.pointerId of a PointerEvent object.
Return value
A boolean value — true if the element does have pointer capture for the pointer identified by the given pointer ID, false if it doesn't.
Examples
<div id="target">Touch this element with a pointer.</div>
const el = document.getElementById("target");
el.addEventListener("pointerdown", (ev) => {
// Element 'target' will receive/capture further events
el.setPointerCapture(ev.pointerId);
// …
// Check whether element still has pointer capture
const pointerCap = el.hasPointerCapture(ev.pointerId);
if (pointerCap) {
// We've still got pointer capture
} else {
// oops, we've lost pointer capture!
}
});
Specifications
Browser compatibility
See also
- Element.setPointerCapture()
- Element.releasePointerCapture()
- Pointer_events
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
