fn

getTranslate

v0.0.5

Reads the current translation of an element along one axis from its computed transform, parsing both matrix(...) (2D) and matrix3d(...) (3D) forms. Returns null when the element has no matrix transform.

Example

ts
const offset = getTranslate(panel, 'y'); // px the panel is shifted down

Signature

ts
declare function getTranslate(element: HTMLElement, axis: TranslateAxis): number | null;

Parameters

ParameterTypeDescription
elementHTMLElementThe element to measure
axisTranslateAxis'x' for horizontal, 'y' for vertical

Returns

number | nullThe translation in pixels, or null if none