Element.releasePointerCapture() - Web APIs 编辑
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 2 The definition of 'releasePointerCapture' in that specification. | Recommendation | Non-stable version. |
Pointer Events The definition of 'releasePointerCapture' in that specification. | Obsolete | Initial definition. |
Browser compatibility
BCD tables only load in the browser
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论