DOM & EventsBaseline · Widely

Pointer Events, touch-action, and Pointer Capture

Mental Model

Pointer Events unify mouse, touch, and stylus input into one stream (pointerdown, pointermove, pointerup). Declaring CSS touch-action tells the compositor which gestures belong to the browser (preventing pointercancel mid-drag without sacrificing Passive Event Listeners) while setPointerCapture() locks fast drags to the handle.

Interactive Simulator

Pointer Events, touch-action, and setPointerCapture

Trace compositor touch-action negotiation, pointer capture, and pointercancel prevention.

Compositor Hit-Test
pointerdown
Pointer Capture
Step 1 / 3: 1. Compositor Reads touch-action

Before JS runs, compositor checks touch-action: pan-y on the slider track (horizontal drag owned by JS).

.slider-thumb { touch-action: pan-y; }
Internal State / Memory
touchAction
pan-y
compositorOwns
vertical scroll
jsOwns
horizontal drag

Under the Hood

At touchstart, the compositor thread reads CSS touch-action off the hit-tested layer to decide whether native pan/zoom owns the gesture without waiting for main-thread JS. Like painting dedicated bike lanes before rush hour, touch-action: none reserves the stream for your drag handler so the browser never fires pointercancel mid-drag.

  1. Compositor Pre-Check: At touchstart, the compositor reads touch-action (none, pan-x, pan-y, manipulation) without waiting for JS.
  2. No pointercancel: On touch-action: none, the browser suppresses native pan/zoom so pointermove streams cleanly.
  3. Pointer Capture: Calling el.setPointerCapture(e.pointerId) redirects all subsequent DOM Event Propagation for that pointer straight to el until pointerup.
JS
knob.addEventListener('pointerdown', (e) => {
  knob.setPointerCapture(e.pointerId);
  knob.dataset.dragging = 'true';
});
knob.addEventListener('pointermove', (e) => {
  if (knob.dataset.dragging === 'true') moveKnob(e.clientX);
});
knob.addEventListener('pointerup', () => delete knob.dataset.dragging);

Problem Genealogy

  • 2008 (Split Mouse & Touch Events): Developers duplicated mousedown/mousemove and touchstart/touchmove handlers with 300 ms tap delays.
  • 2015 (W3C Pointer Events): Unified input coordinates, pressure, tilt, and pointerId across all devices.
  • 2019 (Universal touch-action: manipulation): Eliminated the 300 ms double-tap zoom delay on interactive controls.

Production Pitfalls

Production Pitfall
  • Missing touch-action on Sliders: Forgetting touch-action: pan-y on a horizontal carousel causes mobile browsers to abort drags with pointercancel.
  • Orphaned Drag State: Relying on pointerup on the knob without setPointerCapture() drops the release event when the cursor leaves the element.
When Not to Use
  • When not to use touch-action: none: Never apply touch-action: none to large scrollable sections, it traps mobile users who try to scroll past the widget.

Connections & Logical Next Steps

DOM & EventsPointer Events, touch-action, and Pointer Capture
What This Unlocks
Leaf concept

Mechanical Comparisons