files/en-us/web/api/element/releasepointercapture/index.md
{{APIRef("DOM")}}
The releasePointerCapture() method of the
{{domxref("Element")}} interface releases (stops) pointer capture that was
previously set for a specific ({{domxref("PointerEvent")}}) pointer.
releasePointerCapture(pointerId)
pointerId
None ({{jsxref("undefined")}}).
NotFoundError {{domxref("DOMException")}}
pointerId does not match any active pointer.This example sets pointer capture on a {{HtmlElement("div")}} when you press down on it. This lets you slide the element horizontally, even when your pointer moves outside of its boundaries.
<div id="slider">SLIDE ME</div>
div {
width: 140px;
height: 50px;
display: flex;
align-items: center;
justify-content: center;
background: #ffbbee;
}
const slider = document.getElementById("slider");
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)`;
}
slider.onpointerdown = beginSliding;
slider.onpointerup = stopSliding;
{{EmbedLiveSample("Examples")}}
{{Specifications}}
{{Compat}}