const transform = new CSSTransformValue([
new CSSTranslate(CSS.px(10), CSS.px(20)),
new CSSScale(2, 3),
]);
console.log(transform.length); // 2
console.log(transform[0].toString()); // "translate(10px, 20px)"
for (const component of transform) {
console.log(component.toString());
}
// "translate(10px, 20px)"
// "scale(2, 3)"
transform[1] = new CSSScale(4, 5);
console.log(transform[1].toString()); // "scale(4, 5)"CSSTransformValue / notebook
CSSTransformValue
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
<button id="btn">Styled button</button>#btn {
display: inline-block;
transform: scale(0.95);
}const styleMap = document.getElementById("btn").computedStyleMap();
const transform = styleMap.get("transform");
console.log(transform); // CSSTransformValue {0: CSSScale, length: 1, is2D: true}
console.log(transform.length); // 1
console.log(transform[0].x); // CSSUnitValue {value: 0.95, unit: "number"}
console.log(transform.is2D); // true