The releasePointerCapture()
method of the Element
interface 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);
Parameters
pointerId
- The
pointerId
of aPointerEvent
object.
Return value
This method returns undefined
.
Exceptions
Exception | Explanation |
---|---|
InvalidPointerId
|
pointerId does not match any of the active pointers. |
Example
This example sets pointer capture on a <div>
when you press down on it. This lets you slide the element horizontally, even when you pointer moves outside of its boundaries.
HTML
<div id="slider">SLIDE ME</div>
CSS
div {
width: 140px;
height: 50px;
display: flex;
align-items: center;
justify-content: center;
background: #fbe;
}
JavaScript
function beginSliding(e) {
slider.onpointermove = slide;
slider.setPointerCapture(e.pointerId);
}
function stopSliding(e) {
slider.onpointermove = null;
slider.releasePointerCapture(e.pointerId);
}
function slide(e) {
slider.style.transform = `translate(${e.clientX - 70}px)`;
}
const slider = document.getElementById('slider');
slider.onpointerdown = beginSliding;
slider.onpointerup = stopSliding;
Result
Specifications
Specification | Status | Comment |
Pointer Events – Level 2The definition of 'releasePointerCapture' in that specification. | Recommendation | Non-stable version. |
Pointer EventsThe definition of 'releasePointerCapture' in that specification. | Obsolete | Initial definition. |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
releasePointerCapture
|
Chrome
Full support 55 |
Edge
Full support 12 |
Firefox Full support 59 Full support 59 Full support 41 Disabled' From version 41: this feature is behind the |
IE Full support 11 Full support 11 Full support 10 Prefixed' Implemented with the vendor prefix: ms |
Opera
Full support 42 |
Safari
Full support 13 |
WebView Android
Full support 55 |
Chrome Android
Full support 55 |
Firefox Android No support No No support No Full support 41 Disabled' From version 41: this feature is behind the |
Opera Android
Full support 42 |
Safari iOS
Full support 13 |
Samsung Internet Android
Full support 6.0 |
Legend
- Full support
- Full support
- No support
- No support
- User must explicitly enable this feature.'
- User must explicitly enable this feature.
- Requires a vendor prefix or different name for use.'
- Requires a vendor prefix or different name for use.
See also
Element.releasePointerCapture() by Mozilla Contributors is licensed under CC-BY-SA 2.5.