You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: css-transforms-1/Overview.bs
+90-70
Original file line number
Diff line number
Diff line change
@@ -145,6 +145,14 @@ When used in this specification, terms have the meanings assigned in this sectio
145
145
: <dfn>identity transform function</dfn>
146
146
:: A <a href="#transform-functions">transform function</a> that is equivalent to a identity 4x4 matrix (see <a href="#mathematical-description">Mathematical Description of Transform Functions</a>). Examples for identity transform functions are ''translate(0)'', ''translateX(0)'', ''translateY(0)'', ''scale(1)'', ''scaleX(1)'', ''scaleY(1)'', ''rotate(0)'', ''skew(0, 0)'', ''skewX(0)'', ''skewY(0)'' and ''matrix(1, 0, 0, 1, 0, 0)''.
147
147
148
+
: <dfn>post-multiply</dfn>
149
+
:: Term <var>A</var> post-multiplied by term <var>B</var> is equal to <var>A</var> · <var>B</var>.
150
+
151
+
: <dfn>pre-multiply</dfn>
152
+
:: Term <var>A</var> pre-multiplied by term <var>B</var> is equal to <var>B</var> · <var>A</var>.
153
+
154
+
: <dfn>multiply</dfn>
155
+
:: Multiply term <var>A</var> by term <var>B</var> is equal to <var>A</var> · <var>B</var>.
148
156
149
157
The Transform Rendering Model {#transform-rendering}
@@ -156,22 +164,23 @@ Specifying a value other than ''transform/none'' for the 'transform' property es
156
164
The coordinate space is a coordinate system with two axes: the X axis increases horizontally to the right; the Y axis increases vertically downwards.
157
165
158
166
<p id="transformation-matrix-computation">
159
-
The [=transformation matrix=] is computed from the 'transform' and 'transform-origin' properties as follows:
167
+
The [=transformation matrix=] is computed from the 'transform' and 'transform-origin' properties as follows:
160
168
161
-
1. Start with the identity matrix.
162
-
2. Translate by the computed X and Y of 'transform-origin'
163
-
3. Multiply by each of the transform functions in 'transform' property from left to right
164
-
4. Translate by the negated computed X and Y values of 'transform-origin'
169
+
1. Start with the identity matrix.
170
+
2. Translate by the computed X and Y of 'transform-origin'
171
+
3. Multiply by each of the transform functions in 'transform' property from left to right
172
+
4. Translate by the negated computed X and Y values of 'transform-origin'
165
173
166
174
Transforms apply to [=transformable elements=].
167
175
168
176
Note: Transformations do affect the visual rendering, but have no affect on the CSS layout other than affecting overflow. Transforms are also taken into account when computing client rectangles exposed via the Element Interface Extensions, namely <a href="https://www.w3.org/TR/cssom-view/#dom-element-getclientrects">getClientRects()</a> and <a href="https://www.w3.org/TR/cssom-view/#dom-element-getboundingclientrect">getBoundingClientRect()</a>, which are specified in [[CSSOM-VIEW]].
169
177
170
178
<div class="example">
171
-
<pre>
172
-
div {
173
-
transform: translate(100px, 100px);
174
-
}</pre>
179
+
<pre><code highlight=css>
180
+
div {
181
+
transform: translate(100px, 100px);
182
+
}
183
+
</code></pre>
175
184
176
185
This transform moves the element by 100 pixels in both the X and Y directions.
177
186
@@ -182,13 +191,13 @@ div {
182
191
</div>
183
192
184
193
<div class="example">
185
-
<pre>
194
+
<pre><code highlight=css>
186
195
div {
187
196
height: 100px; width: 100px;
188
197
transform-origin: 50px 50px;
189
198
transform: rotate(45deg);
190
199
}
191
-
</pre>
200
+
</code></pre>
192
201
193
202
The 'transform-origin' property moves the point of origin by 50 pixels in both the X and Y directions. The transform rotates the element clockwise by 45° about the point of origin. After all transform functions were applied, the translation of the origin gets translated back by -50 pixels in both the X and Y directions.
194
203
@@ -198,28 +207,35 @@ The 'transform-origin' property moves the point of origin by 50 pixels in both t
This transformation translates the local coordinate system by 80 pixels in both the X and Y directions, then applies a 150% scale, then a 45° clockwise rotation about the Z axis. The impact on the rendering of the element can be intepreted as an application of these transforms in reverse order: the elements is rotated, then scaled, then translated.
217
+
The visual appareance is as if the <a element>div</a> element gets translated by 80px to the bottom left direction, then scaled up by 150% and finally rotated by 45°.
Each <<transform-function>> can get represented by a corresponding 4x4 matrix. To map a point from the coordinate space of the <a element>div</a> box to the coordinate space of the parent element, these transforms get multiplied in the reverse order:
220
+
1. The rotation matrix gets multiplied with the scale matrix.
221
+
2. The result of the previous multiplication is then multiplied with the translation matrix to create the accumulated transformation matrix.
222
+
3. Finally, the point to map gets pre-multiplied with the accumulated transformation matrix.
223
+
224
+
For more details see <a href="#transform-function-lists">The Transform Function Lists</a>.
For elements whose layout is governed by the CSS box model, the transform property does not affect the flow of the content surrounding the transformed element. However, the extent of the overflow area takes into account transformed elements. This behavior is similar to what happens when elements are offset via relative positioning. Therefore, if the value of the 'overflow' property is ''overflow/scroll'' or ''overflow/auto'', scrollbars will appear as needed to see content that is transformed outside the visible area. Specifically, transforms can extend (but do not shrink) the size of the overflow area, which is computed as the union of the bounds of the elements before and after the application of transforms.
@@ -312,11 +328,11 @@ If two or more values are defined and either no value is a keyword, or the only
312
328
</dl>
313
329
314
330
For SVG elements without associated CSS layout box the initial [=used value=] is ''0 0'' as if the user agent style sheet contained:
315
-
<pre>
331
+
<pre><code highlight=css>
316
332
*:not(svg), *:not(foreignObject) > svg {
317
333
transform-origin: 0 0;
318
334
}
319
-
</pre>
335
+
</code></pre>
320
336
321
337
The 'transform-origin' property is a <a>resolved value special case</a> property like 'height'. [[!CSSOM]]
322
338
@@ -378,7 +394,7 @@ Since the previously named SVG attributes become presentation attributes, their
378
394
379
395
This example shows the combination of the 'transform' style property and the <a element-attr for>transform</a> presentation attribute.
380
396
381
-
<pre>
397
+
<pre><code highlight=xml>
382
398
<svg xmlns="http://www.w3.org/2000/svg">
383
399
<style>
384
400
.container {
@@ -390,7 +406,7 @@ This example shows the combination of the 'transform' style property and the <a
@@ -463,7 +479,7 @@ Issue(w3c/csswg-drafts#893): User coordinate space statement breaks SVG.
463
479
464
480
The 'transform-origin' property on the pattern in the following example specifies a ''50%'' translation of the origin in the horizontal and vertical dimension. The 'transform' property specifies a translation as well, but in absolute lengths.
465
481
466
-
<pre>
482
+
<pre><code highlight=xml>
467
483
<svg xmlns="http://www.w3.org/2000/svg">
468
484
<style>
469
485
pattern {
@@ -480,7 +496,7 @@ The 'transform-origin' property on the pattern in the following example specifie
An SVG <{pattern}> element doesn't have a bounding box. The [=reference box=] of the referencing <{rect}> element is used instead to solve the relative values of the 'transform-origin' property. Therefore the point of origin will get translated by 100 pixels temporarily to rotate the user space of the <{pattern}> elements content.
486
502
@@ -507,7 +523,7 @@ With this specification, the <{animate}> element and the <{set}> element can ani
507
523
508
524
The animation effect is post-multiplied to the underlying value for additive <{animate}> animations (see below) instead of added to the underlying value, due to the specific behavior of <<transform-list>> animations.
<var ignore=''>From-to</var>, <var ignore=''>from-by</var> and <var ignore=''>by</var> animations are defined in SMIL to be equivalent to a corresponding <var>values</var> animation. However, <var ignore=''>to</var> animations are a mixture of additive and non-additive behavior [[SMIL3]].
513
529
@@ -557,16 +573,16 @@ Note: This paragraph focuses on the requirements of [[SMIL]] and the extension d
557
573
558
574
<div class="example">
559
575
560
-
A <var>by</var> animation with a by value v<sub>b</sub> is equivalent to the same animation with a values list with 2 values, the neutral element for addition for the domain of the target attribute (denoted 0) and v<sub>b</sub>, and ''additive="sum"''. [[SMIL3]]
576
+
A <var>by</var> animation with a by value v<sub>b</sub> is equivalent to the same animation with a values list with 2 values, the neutral element for addition for the domain of the target attribute (denoted 0) and v<sub>b</sub>, and ''additive="sum"''. [[SMIL3]]
The neutral element for addition when performing a <var>by</var> animation with ''type="scale"'' is the value 0. Thus, performing the animation of the example above causes the rectangle to be invisible at time 0s (since the animated transform list value is ''scale(0)''), and be scaled back to its original size at time 5s (since the animated transform list value is ''scale(1)'').
585
+
The neutral element for addition when performing a <var>by</var> animation with ''type="scale"'' is the value 0. Thus, performing the animation of the example above causes the rectangle to be invisible at time 0s (since the animated transform list value is ''scale(0)''), and be scaled back to its original size at time 5s (since the animated transform list value is ''scale(1)'').
570
586
571
587
</div>
572
588
@@ -579,12 +595,14 @@ The SVG '<a href="https://www.w3.org/TR/SVG/animate.html#TargetAttributes">attri
579
595
580
596
In this example the gradient transformation of the linear gradient gets animated.
The <{linearGradient}> element specifies the <{linearGradient/gradientTransform}> presentation attribute. The two <{animate}> elements address the target attribute <{linearGradient/gradientTransform}> and 'transform'. Even so all animations apply to the same gradient transformation by taking the value of the <{linearGradient/gradientTransform}> presentation attribute, applying the scaling of the first animation and applying the translation of the second animation one after the other.
590
608
@@ -666,32 +684,34 @@ The Transform Function Lists {#transform-function-lists}
666
684
667
685
If a list of <<transform-function>> is provided, then the net effect is as if each transform function had been specified separately in the order provided. For example,
That is, in the absence of other styling that affects position and dimensions, a nested set of transforms is equivalent to a single list of transform functions, applied from the top ancestor (with the id <code>root</code>) to the deepest descendant (with the id <code>child</code>). The resulting transform is the matrix multiplication of the list of transforms.
685
705
686
-
That is, in the absence of other styling that affects position and dimensions, a nested set of transforms is equivalent to a single list of transform functions, applied from the outside in. The resulting transform is the matrix multiplication of the list of transforms.
706
+
Issue(w3c/csswg-drafts#909): Backport point mapping from one coordinate space to another from SVG.
687
707
688
708
If a transform function causes the [=current transformation matrix=] of an object to be non-invertible, the object and its content do not get displayed.
689
709
690
710
<div class="example">
691
711
692
712
The object in the following example gets scaled by 0.
693
713
694
-
<pre>
714
+
<pre><code highlight=html>
695
715
<style>
696
716
.box {
697
717
transform: scale(0);
@@ -701,7 +721,7 @@ The object in the following example gets scaled by 0.
701
721
<div class="box">
702
722
Not visible
703
723
</div>
704
-
</pre>
724
+
</code></pre>
705
725
706
726
The scaling causes a non-invertible CTM for the coordinate space of the div box. Therefore neither the div box, nor the text in it get displayed.
707
727
@@ -772,7 +792,7 @@ Two different types of transform functions that share the same primitive, or tra
772
792
The following example describes a transition from ''translateX(100px)'' to ''translateY(100px)'' in 3 seconds on hovering over the div box. Both transform functions derive from the same primitive ''translate()''
773
793
and therefore can be interpolated.
774
794
775
-
<pre>
795
+
<pre><code highlight=css>
776
796
div {
777
797
transform: translateX(100px);
778
798
}
@@ -781,7 +801,7 @@ and therefore can be interpolated.
781
801
transform: translateY(100px);
782
802
transition: transform 3s;
783
803
}
784
-
</pre>
804
+
</code></pre>
785
805
786
806
For the time of the transition both transform functions get transformed to the common primitive. ''translateX(100px)'' gets converted to ''translate(100px, 0)'' and ''translateY(100px)'' gets converted to ''translate(0, 100px)''. Both transform functions can then get interpolated numerically.
787
807
</div>
@@ -792,7 +812,7 @@ If both transform functions share a primitive in the two-dimensional space, both
792
812
793
813
In this example a two-dimensional transform function gets animated to a three-dimensional transform function. The common primitive is ''translate3d()''.
794
814
795
-
<pre>
815
+
<pre><code highlight=css>
796
816
div {
797
817
transform: translateX(100px);
798
818
}
@@ -801,7 +821,7 @@ In this example a two-dimensional transform function gets animated to a three-di
801
821
transform: translateZ(100px);
802
822
transition: transform 3s;
803
823
}
804
-
</pre>
824
+
</code></pre>
805
825
806
826
First ''translateX(100px)'' gets converted to ''translate3d(100px, 0, 0)'' and ''translateZ(100px)'' to ''translate3d(0, 0, 100px)'' respectively. Then both converted transform functions get interpolated numerically.
807
827
@@ -813,27 +833,27 @@ Interpolation of Matrices {#matrix-interpolation}
813
833
814
834
When interpolating between two matrices, each matrix is decomposed into the corresponding translation, rotation, scale, skew. Each corresponding component of the decomposed matrices gets interpolated numerically and recomposed back to a matrix in a final step.
815
835
836
+
<div class="example">
816
837
In the following example the element gets translated by 100 pixel in both the X and Y directions and rotated by 1170° on hovering. The initial transformation is 45°. With the usage of transition, an author might expect a animated, clockwise rotation by three and a quarter turns (1170°).
The number of transform functions on the source transform ''rotate(45deg)'' differs from the number of transform functions on the destination transform ''translate(100px, 100px) rotate(1125deg)''. According to the last rule of <a href="#interpolation-of-transforms">Interpolation of Transforms</a>, both transforms must be interpolated by matrix interpolation. With converting the transformation functions to matrices, the information about the three turns gets lost and the element gets rotated by just a quarter turn (90°).
835
854
836
855
To achieve the three and a quarter turns for the example above, source and destination transforms must fulfill the third rule of <a href="#interpolation-of-transforms">Interpolation of Transforms</a>. Source transform could look like ''translate(0, 0) rotate(45deg)'' for a linear interpolation of the transform functions.
856
+
</div>
837
857
838
858
In the following we differ between the <a href="#interpolation-of-2d-matrices">interpolation of two 2D matrices</a> and the interpolation of two matrices where at least one matrix is not a [=2D matrix=].
0 commit comments