Element.setPointerCapture()

这篇翻译不完整。请帮忙从英语翻译这篇文章

Pointer capture 允许一个特定的pointer event (PointerEvent) 事件从一个事件触发时候的目标重定位到另一个目标上。这个功能可以确保一个元素可以持续的接收到一个pointer事件,即使这个事件的触发点已经移出了这个元素(比如,在滚动的时候)。

setPointerCapture() 是一个Element接口上的一个方法,用来明确指明一个元素作为pointer eventscapture target。所有类型的pointer事件都将定位到capture element ,直到capture被释放(参考:Element.releasePointerCapture)。 

一旦设置了pointer capture, pointerover, pointerout pointerenterpointerleave 事件将不会被触发,直到越过设置了capture的元素的边界。这是因为其他元素将不能再作为pointer事件的目标了。这会影响到这些事件在其他元素上的触发。

语法

targetElement.setPointerCapture(pointerId);

参数

pointerId
 pointer eventidentifier

返回值

返回void。如果pointerId不匹配任何当前活动的pointers事件,将抛出DOMException

示例

<html>
<script>
function downHandler(ev) {
 var el=document.getElementById("target");
 //Element 'target' will receive/capture further events
 el.setPointerCapture(ev.pointerId);
}
function init() {
 var el=document.getElementById("target");
 el.onpointerdown = downHandler;
}
</script>
<body onload="init();">
<div id="target"> Touch me ... </div>
</body>
</html>

规范

Specification Status Comment
Pointer Events – Level 2
setPointerCapture
Working Draft Non-stable version.
Pointer Events
setPointerCapture
Recommendation Initial definition.

浏览器兼容性

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 35[1] 59 (59) 10 -ms
11
? 未实现
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support ? 35[1] 29.0 (29)[2] 10 -ms
11
? 未实现

[1] This was implemented in bug 248918.

[2] Supported behind the preference dom.w3c_pointer_events.enabled, defaulting to false.

 

相关链接

文档标签和贡献者

此页面的贡献者: waitkafuka
最后编辑者: waitkafuka,