元素:hasPointerCapture() 方法
语法
js
hasPointerCapture(pointerId)
参数
pointerId
-
pointerId
是PointerEvent
对象的属性。
返回值
一个布尔值——如果元素确实针对给定指针 ID 所标识的指针捕获了指针,则为true
,否则为false
。
示例
html
<html lang="en">
<script>
function downHandler(ev) {
const el = document.getElementById("target");
// Element 'target' will receive/capture further events
el.setPointerCapture(ev.pointerId);
// …
// Check whether element still has pointer capture
let pointerCap = el.hasPointerCapture(ev.pointerId);
if (pointerCap) {
// We've still got pointer capture
} else {
// oops, we've lost pointer capture!
}
}
function init() {
const el = document.getElementById("target");
el.onpointerdown = downHandler;
}
</script>
<body onload="init();">
<div id="target">Touch this element with a pointer.</div>
</body>
</html>
规范
规范 |
---|
指针事件 # dom-element-haspointercapture |
浏览器兼容性
BCD 表格仅在浏览器中加载