Are css transform matrix and transform scale, skew, translate equivalent?
According to this answer css transform matrix values are equivalent to the rotate, skew and scale functions, however this post makes it seem much more complex...
arguments a and d are for scaling the element. Identical to that of the scale(a, d) method.
arguments b and c are for skewing the element. Identical to that of the skew(b, c) method.
arguments e and f are for translating the element. Identical to that of the translate(e, f) method.
Is the transform matrix actually that simple?
So the following 2 transforms would be identical
.scale-in {
transform: scale(3,3) translate(200px, 200px);
}
.scale-in-matrix {
transform: matrix(3, 0, 0, 3, 200, 200);
}
The transform CSS property lets you rotate, scale, skew, or translate an element. It modifies the coordinate space of the CSS visual formatting model.
CSS Demo: skew() This transformation is a shear mapping (transvection) that distorts each point within an element by a certain angle in the horizontal and vertical directions. The effect is as if you grabbed each corner of the element and pulled them along a certain angle.
transform-origin changes the point at which the element transforms rather than moving the entire element (as translate would). The default value is transform-origin: 50% 50%; .
They are not exactly equivalent
CSS transforms are NOT commutative. Most mathematic operations are commutative, meaning that the order they are applied doesn't matter. But transforms are not. The order is very important, and it is the reason we see different results here when scale and translation is swapped around.
So, the following transform
transform: scale(2,2) translate(-100px,-50px);
is not equivalent to
transform: translate(-100px,-50px) scale(2,2);
In the first case, you first zoom, and after that you translate
In the second example we see it move smoother, as it first translates and then scales. Because it first has translated in, the scale is not multiplied in this case, so we can give an equivalent value for the translation
transform: matrix(2, 0, 0, 2, -200, -100);
is actually equivalent to
transform: translate(-200px,-100px) scale(2,2);
And this is due to the ordering, in this case they both have the same order, and translation position is not multiplied by the scale.
An updated codepen example
Another answer to a similar question which cleared up the issue, thanks to Vals
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With