Performance: Transform property
The transform property affects how elements are visually changed without affecting layout, improving animation and interaction speed.
Jump into concepts and practice - no test required
element.style.transform = 'translateX(100px)';
element.style.left = '100px';
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Changing 'left' property | 1 DOM update | 1 reflow per frame | 1 repaint per frame | [X] Bad |
| Using 'transform: translateX()' | 1 DOM update | 0 reflows | 0 repaints | [OK] Good |
transform property do?transformtransform property visually changes elements by moving, rotating, scaling, or skewing them.transform.transform?rotate function requires parentheses and a unit, like rotate(45deg).div {
transform: translateX(50px) scale(2);
width: 100px;
height: 100px;
background-color: blue;
}translateX(50px) moves the element 50 pixels to the right. scale(2) doubles the element's size.p {
transform: rotate 30deg;
}rotate function requires parentheses around the angle, like rotate(30deg).transform. Rotate works on any element.transform property correctly combines these effects?scale(1.5) rotate(90deg).