After combing through the SVG specification, and guides such as this and this, I am still struggling to understand exactly how chaining transforms work.
Selected Relevant Quotes
When you apply the transform attribute to an SVG element, that element
gets a "copy" of the current user coordinate system in use.
And:
When transformations are chained, the most important thing to be aware
of is that, just like with HTML element transformations, each
transformation is applied to the coordinate system after that system
is transformed by the previous transformations.
And:
For example, if you’re going to apply a rotation to an element,
followed by a translation, the translation happens according to the
new coordinate system, not the inital non-rotated one.
And:
The sequence of transformations matter. The sequence the
transformation functions are specified inside the transform attribute
is the sequence they are applied to the shape.
Code
The first rectangle's current coordinate system is scaled, then rotated (note the order). The second rectangle's current coordinate system is rotated, then scaled.
svg {
border: 1px solid green;
}
<svg xmlns="http://www.w3.org/2000/svg">
<style>
rect#s1 {
fill: red;
transform: scale(2, 1) rotate(10deg);
}
</style>
<rect id="s1" x="" y="" width="100" height="100" />
</svg>
<svg xmlns="http://www.w3.org/2000/svg">
<style>
rect#s2 {
fill: blue;
transform: rotate(10deg) scale(2, 1);
}
</style>
<rect id="s2" x="" y="" width="100" height="100" />
</svg>
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…