MDN self-hosted library · e01.org

CSSTransformComponent: toMatrix() method

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

js
const translate = new CSSTranslate(CSS.px(10), CSS.px(20));

const matrix = translate.toMatrix();
console.log(matrix.e, matrix.f); // 10 20
js
const translate = new CSSTranslate(CSS.percent(50), CSS.px(20));

try {
  translate.toMatrix();
} catch (e) {
  console.log(e); // TypeError
}