viewportToElement
Commons
stable
Convert a point expressed in viewport (page) coordinates to the local coordinate space of an element by subtracting the element's bounding-box offset.
API
Signature
Full TypeScript signature sourced from the util file.
API
Parameters
Input parameters accepted by this util.
- pointrequiredTViewportPoint
- The { x, y } point in viewport (screen) coordinates, e.g. from a pointer event's clientX/clientY.
- offsetrequiredTOffset | IBox
- The element's bounding box or a plain { x, y } offset (e.g. from getBoundingClientRect()).
API
Return value
The value returned by this util.
- The { x, y } point in the element's local coordinate space.
Usage
Examples
Ready-to-paste usage snippets.
Translate a click position into element space