Element.releasePointerCapture()

我们的志愿者还没有将这篇文章翻译为 中文 (简体)加入我们帮助完成翻译
您也可以阅读此文章的English (US)版。

Releases (stops) pointer capture that was previously set for a specific (PointerEvent) pointer.

See the Element.setPointerCapture() method for a description of pointer capture and how to set it for a particular element.

Syntax

targetElement.releasePointerCapture(pointerId);

Arguments

pointerId
The identifier for a pointer event.

Return value

If pointerId does not match any the active pointers, this method returns void and throws a DOMException with the name InvalidPointerId.

Example

<html>
<script>
function downHandler(ev) {
 var el=document.getElementById("target");
 // Element "target" will receive/capture further events
 el.setPointerCapture(ev.pointerId);
}
function cancelHandler(ev) {
 var el=document.getElementById("target");
 // Release the pointer capture
 el.releasePointerCapture(ev.pointerId);
}
function init() {
 var el=document.getElementById("target");
 // Register pointerdown and pointercancel handlers
 el.onpointerdown = downHandler;
 el.onpointercancel = cancelHandler;
}
</script>
<body onload="init();">
<div id="target"> Touch me ... </div>
</body>
</html>

Specifications

Specification Status Comment
Pointer Events – Level 2
The definition of 'releasePointerCapture' in that specification.
Working Draft Non-stable version.
Pointer Events
The definition of 'releasePointerCapture' in that specification.
Recommendation Initial definition.

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support55 ?

59

411

11

10 ms

42 No
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support5555 ?

No

411

42 No ?

1. From version 41: this feature is behind the dom.w3c_pointer_events.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.

See also

文档标签和贡献者

此页面的贡献者: fscholz, chrisdavidmills, erikadoyle, rolfedh, AFBarstow
最后编辑者: fscholz,