setPointerCapture method
The setPointerCapture()
method of the
Element
interface is used to designate a specific element as the
capture target of future pointer events. Subsequent events for the
pointer will
be targeted at the capture element until capture is released (via
Element.releasePointerCapture
or the
Element.pointerup_event
event is fired).
Note: Pointer capture will cause the target to capture all subsequent pointer events as if they were occurring over the capturing target. Accordingly,
pointerover
,pointerenter
,pointerleave
, andpointerout
will not fire as long as this capture is set. For touchscreen browsers that allow direct manipulation, an implicit pointer capture will be called on the element when apointerdown
event triggers. The capture can be released manually by callingelement.releasePointerCapture
on the target element, or it will be implicitly released after apointerup
orpointercancel
event.
Note: If you need to move an element in the DOM, then make sure to call
setPointerCapture()
after DOM movements so thatsetPointerCapture()
will not lose track of it. E.g., if you need to useElement.append()
to move an element somewhere else, then make sure to callsetPointerCapture()
on it only after the call toElement.append()
.
Overview of pointer capture
Pointer capture allows events for a particular pointer event
(PointerEvent
) to be re-targeted to a particular element instead of the
normal (or hit test) target at a pointer's location. This can be used to
ensure
that an element continues to receive pointer events even if the pointer
device's contact
moves off the element (such as by scrolling or panning).
Implementation
external void setPointerCapture(int pointerId);