getPosition

Commons
stable

Extracts a named client coordinate (e.g. clientX, pageY) from a MouseEvent or TouchEvent in a unified way, handling both touch and pointer events transparently.

API

Signature

Full TypeScript signature sourced from the util file.

typescript

API

Parameters

Input parameters accepted by this util.

e
required
MouseEvent | TouchEvent
The native DOM event. Touch events are read via e.touches[0] (or changedTouches[0] for touchend); mouse events are read directly.
position
required
TClientPosition
The coordinate key to read, e.g. "clientX", "clientY", "pageX", "pageY", "screenX", "screenY".

API

Return value

The value returned by this util.

The numeric coordinate value in pixels from the requested position property.

Usage

Examples

Ready-to-paste usage snippets.

Unified pointer coordinate from mouse or touch

typescript