Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. Element
  4. releasePointerCapture()

Element: releasePointerCapture() method

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨July 2020⁩.

ThereleasePointerCapture() method of theElement interface releases (stops)pointer capture that waspreviously set for a specific (PointerEvent)pointer.

Syntax

js
releasePointerCapture(pointerId)

Parameters

pointerId

ThepointerId of aPointerEvent object.

Return value

None (undefined).

Exceptions

NotFoundErrorDOMException

Thrown ifpointerId does not match any active pointer.

Examples

This example sets pointer capture on a<div> when you press down onit. This lets you slide the element horizontally, even when your pointer moves outside ofits boundaries.

HTML

html
<div>SLIDE ME</div>

CSS

css
div {  width: 140px;  height: 50px;  display: flex;  align-items: center;  justify-content: center;  background: #ffbbee;}

JavaScript

js
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;

Result

Specifications

Specification
Pointer Events
# dom-element-releasepointercapture

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp