forked from w3c/csswg-drafts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOverview.html
More file actions
1324 lines (1058 loc) · 47.7 KB
/
Overview.html
File metadata and controls
1324 lines (1058 loc) · 47.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang=en>
<head>
<title>CSS 2D Transforms Module Level 3</title>
<link href=default.css rel=stylesheet type="text/css">
<style type="text/css">
.rhs { white-space: pre-wrap; }
code { font-size: inherit; }
#box-shadow-samples td { background: white; color: black; }
</style>
<link href="http://www.w3.org/StyleSheets/TR/W3C-ED.css" rel=stylesheet
type="text/css">
<body>
<div class=head> <!--begin-logo-->
<p><a href="http://www.w3.org/"><img alt=W3C height=48
src="http://www.w3.org/Icons/w3c_home" width=72></a> <!--end-logo-->
<h1>CSS 2D Transforms Module Level 3</h1>
<h2 class="no-num no-toc" id=longstatus-date>Editor's Draft 23 March 2010</h2>
<dl>
<dt>This version:
<dd> <a
href="http://www.w3.org/TR/2010/ED-css3-2d-transforms-20100323">http://dev.w3.org/csswg/css3-2d-transforms/</a>
<!--http://www.w3.org/TR/2010/WD-css3-2d-transforms-20100323-->
<dt>Latest version:
<dd><a
href="http://www.w3.org/TR/css3-2d-transforms">http://www.w3.org/TR/css3-2d-transforms</a>
<dt>Previous version:
<dd><a href="http://www.w3.org/TR/2009/WD-css3-2d-transforms-20090320/">
http://www.w3.org/TR/2009/WD-css3-2d-transforms-20090320/</a>
<dt id=editors-list>Editors:
<dd><a href="mailto:dino@apple.com">Dean Jackson</a> (<a
href="http://www.apple.com/">Apple Inc</a>)
<dd><a href="mailto:hyatt@apple.com">David Hyatt</a> (<a
href="http://www.apple.com/">Apple Inc</a>)
<dd><a href="mailto:cmarrin@apple.com">Chris Marrin</a> (<a
href="http://www.apple.com/">Apple Inc</a>)
</dl>
<!--begin-copyright-->
<p class=copyright><a
href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright"
rel=license>Copyright</a> © 2010 <a
href="http://www.w3.org/"><acronym title="World Wide Web
Consortium">W3C</acronym></a><sup>®</sup> (<a
href="http://www.csail.mit.edu/"><acronym title="Massachusetts Institute
of Technology">MIT</acronym></a>, <a href="http://www.ercim.eu/"><acronym
title="European Research Consortium for Informatics and
Mathematics">ERCIM</acronym></a>, <a
href="http://www.keio.ac.jp/">Keio</a>), All Rights Reserved. W3C <a
href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>,
<a
href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a>
and <a
href="http://www.w3.org/Consortium/Legal/copyright-documents">document
use</a> rules apply.</p>
<!--end-copyright-->
<hr title="Separator for header">
</div>
<h2 class="no-num no-toc" id=abstract>Abstract</h2>
<p>CSS 2D Transforms allows elements rendered by CSS to be transformed in
two-dimensional space.
<h2 class="no-num no-toc" id=status>Status of this document</h2>
<!--begin-status-->
<p>This is a public copy of the editors' draft. It is provided for
discussion only and may change at any moment. Its publication here does
not imply endorsement of its contents by W3C. Don't cite this document
other than as work in progress.
<p>The (<a
href="http://lists.w3.org/Archives/Public/www-style/">archived</a>) public
mailing list <a
href="mailto:www-style@w3.org?Subject=%5Bcss3-2d-transforms%5D%20PUT%20SUBJECT%20HERE">
www-style@w3.org</a> (see <a
href="http://www.w3.org/Mail/Request">instructions</a>) is preferred for
discussion of this specification. When sending e-mail, please put the text
“css3-2d-transforms” in the subject, preferably like this:
“[<!---->css3-2d-transforms<!---->] <em>…summary of
comment…</em>”
<p>This document was produced by the <a href="/Style/CSS/members">CSS
Working Group</a> (part of the <a href="/Style/">Style Activity</a>).
<p>This document was produced by a group operating under the <a
href="/Consortium/Patent-Policy-20040205/">5 February 2004 W3C Patent
Policy</a>. W3C maintains a <a href="/2004/01/pp-impl/32061/status"
rel=disclosure>public list of any patent disclosures</a> made in
connection with the deliverables of the group; that page also includes
instructions for disclosing a patent. An individual who has actual
knowledge of a patent which the individual believes contains <a
href="/Consortium/Patent-Policy-20040205/#def-essential">Essential
Claim(s)</a> must disclose the information in accordance with <a
href="/Consortium/Patent-Policy-20040205/#sec-Disclosure">section 6 of the
W3C Patent Policy</a>.</p>
<!--end-status-->
<p> The <a href=ChangeLog>list of changes made to this specification</a> is
available.
<h2 class="no-num no-toc" id=contents>Table of contents</h2>
<!--begin-toc-->
<ul class=toc>
<li><a href="#introduction"><span class=secno>1. </span>Introduction</a>
<li><a href="#transform-property"><span class=secno>2. </span> The <span
class=prop-name>‘<code
class=property>transform</code>’</span> Property </a>
<li><a href="#transform-origin-property"><span class=secno>3. </span> The
<span class=prop-name>‘<code
class=property>transform-origin</code>’</span> Property </a>
<li><a href="#transform-functions"><span class=secno>4. </span> The
Transformation Functions </a>
<li><a href="#transform-values"><span class=secno>5. </span> Transform
Values and Lists </a>
<li><a href="#animation"><span class=secno>6. </span> Transitions and
animations between transform values </a>
<li><a href="#matrix-decomposition"><span class=secno>7. </span> Matrix
decomposition for animation </a>
<ul class=toc>
<li><a href="#d-matrix-to-4x4-matrix-conversion"><span class=secno>7.1.
</span>2D matrix to 4x4 matrix conversion</a>
<li><a href="#unmatrix"><span class=secno>7.2. </span>Unmatrix</a>
<li><a href="#animating-the-components"><span class=secno>7.3.
</span>Animating the components</a>
<li><a href="#recomposing-the-matrix"><span class=secno>7.4.
</span>Recomposing the matrix</a>
</ul>
<li><a href="#dom-interfaces"><span class=secno>8. </span> DOM Interfaces
</a>
<ul class=toc>
<li><a href="#cssmatrix-interface"><span class=secno>8.1. </span>
CSSMatrix </a>
</ul>
<li><a href="#references"><span class=secno>9. </span>References</a>
<ul class=toc>
<li class=no-num><a href="#normative-references">Normative
references</a>
<li class=no-num><a href="#other-references">Other references</a>
</ul>
<li class=no-num><a href="#property-index">Property index</a>
<li class=no-num><a href="#index">Index</a>
</ul>
<!--end-toc-->
<h2 id=introduction><span class=secno>1. </span>Introduction</h2>
<p><em>This section is not normative.</em>
<p> The CSS <a href="http://www.w3.org/TR/REC-CSS2/visuren.html">visual
formatting model</a> describes a coordinate system within which each
element is positioned. Positions and sizes in this coordinate space can be
thought of as being expressed in pixels, starting in the upper left corner
of the parent with positive values proceeding to the right and down.
<p> This coordinate space can be modified with the <span
class=prop-name>‘<code class=property><a
href="#effects">transform</a></code>’</span> property. Using
transform, elements can be translated, rotated and scaled in two
dimensional space. The coordinate space behaves as described in the <a
href="http://www.w3.org/TR/SVG/coords.html#EstablishingANewUserSpace">coordinate
system transformations</a> section of the SVG 1.1 specification. This is a
coordinate system with two axes: the X axis increases horizontally to the
right; the Y axis increases vertically downwards.
<p> Specifying a value other than ‘<code
class=property>none</code>’ for the <span
class=prop-name>‘<code class=property><a
href="#effects">transform</a></code>’</span> property establishes a
new <em>local coordinate system</em> at the element that it is applied to.
Transformations are cumulative. That is, elements establish their local
coordinate system within the coordinate system of their parent. In this
way, a <span class=prop-name>‘<code class=property><a
href="#effects">transform</a></code>’</span> property effectively
accumulates all the <span class=prop-name>‘<code class=property><a
href="#effects">transform</a></code>’</span> properties of its
ancestors. The accumulation of these transforms defines a <em>current
transformation matrix (CTM)</em> for the element.
<p> The transform property does not affect the flow of the content
surrounding the transformed element. However, the value of the overflow
area takes into account transformed elements. This behavior is similar to
what happens when elements are translated via relative positioning.
Therefore, if the value of the <span class=prop-name>‘<code
class=property>overflow</code>’</span> property is <span
class=prop-value>‘<code class=property>scroll</code>’</span>
or <span class=prop-value>‘<code
class=property>auto</code>’</span>, scrollbars will appear as needed
to see content that is transformed outside the visible area.
<p> Any value other than ‘<code class=property>none</code>’ for
the transform results in the creation of both a stacking context and a
containing block. The object acts as a containing block for fixed
positioned descendants.
<div class=todo> Need to go into more detail here about why fixed
positioned objects should do this, i.e., that it's much harder to
implement otherwise.</div>
<div class=issue> There are two roles for transformations in layout: (1)
transformations that adjust the position of the affected content without
changing the normal layout of that content (much like relative
positioning) and (2) transformation of the content prior to layout that
affects the layout of that content. See <a
href="http://lists.w3.org/Archives/Public/www-style/2007Oct/0209">http://lists.w3.org/Archives/Public/www-style/2007Oct/0209</a>
for examples of both cases. The "transform" property (as defined in this
document) is equally useful for both roles. This document is focused on
satisfying the first role. There is, however, an architectural question
that arises because there needs to be a way to distinguish which role an
author of a stylesheet wants. The key question is which is the default
behavior/role for the "transform" property and how is the other
behavior/role indicated by a stylesheet author. If you have an opinion on
this topic, please send feedback.</div>
<div class=issue> What do fixed backgrounds do in transforms? They should
probably ignore the transform completely, since - even transformed - the
object should be acting as "porthole" through which the fixed background
can be viewed in its original form.</div>
<div class=issue> This property should also be applicable to SVG elements.</div>
<div class=issue> We also need to specify that SVG transforms *do* combine
with this transform, e.g., if a <foreignObject> is inside
transformed SVG and then defines a transform of its own. This means we may
potentially have to examine the current SVG transform and combine with it
to set the correct transform.</div>
<!-- ======================================================================================================= -->
<h2 id=transform-property><span class=secno>2. </span> The <span
class=prop-name>‘<code class=property><a
href="#effects">transform</a></code>’</span> Property</h2>
<p> A two-dimensional transformation is applied to an element through the
<span class=prop-name>‘<code class=property><a
href="#effects">transform</a></code>’</span> property. This property
contains a list of <a href="#transform-functions">transform functions</a>.
The final transformation value for an element is obtained by performing a
matrix concatenation of each entry in the list. The set of transform
functions is similar to those allowed by SVG.
<table class=propdef>
<tbody>
<tr>
<td> <em>Name:</em>
<td> <dfn id=effects>transform</dfn>
<tr>
<td> <em>Value:</em>
<td> none | <transform-function> [ <transform-function> ]*
<tr>
<td> <em>Initial:</em>
<td> none
<tr>
<td> <em>Applies to:</em>
<td> block-level and inline-level elements
<tr>
<td> <em>Inherited:</em>
<td> no
<tr>
<td> <em>Percentages:</em>
<td> refer to the size of the element's border box
<tr>
<td> <em>Media:</em>
<td> visual
<tr>
<td> <em>Computed value:</em>
<td> Same as specified value.
</table>
<!-- ======================================================================================================= -->
<h2 id=transform-origin-property><span class=secno>3. </span> The <span
class=prop-name>‘<code class=property><a
href="#transform-origin">transform-origin</a></code>’</span>
Property</h2>
<p> The <span class=prop-name>‘<code class=property><a
href="#transform-origin">transform-origin</a></code>’</span>
property establishes the origin of transformation for an element. This
property is applied by first translating the element by the negated value
of the property, then applying the element's transform, then translating
by the property value. This effectively moves the desired transformation
origin of the element to (0,0) in the local coordinate system, then
applies the element's transform, then moves the element back to its
original position.
<p>If only one value is specified, the second value is assumed to be
‘<code class=property>center</code>’. If two values are given
and at least one value is not a keyword, then the first value represents
the horizontal position (or offset) and the second represents the vertical
position (or offset). <var><percentage></var> and
<var><length></var> values here represent an offset of the transform
origin from the top left corner of the element's border box.
<p>If three or four values are given, then each
<var><percentage></var> or<var><length></var> represents an
offset and must be preceded by a keyword, which specifies from which edge
the offset is given. For example, ‘<code class=css>transform-origin:
bottom 10px right 20px</code>’ represents a ‘<code
class=css>10px</code>’ vertical offset up from the bottom edge and a
‘<code class=css>20px</code>’ horizontal offset leftward from
the right edge. If three values are given, the missing offset is assumed
to be zero.
<p>Positive values represent an offset <em>inward</em> from the edge of the
border box. Negative values represent an offset <em>outward</em> from the
edge of the border box.
<table class=propdef>
<tbody>
<tr>
<td> <em>Name:</em>
<td> <dfn id=transform-origin>transform-origin</dfn>
<tr>
<td> <em>Value:</em>
<td> [ top | bottom ] |<br>
[ <percentage> | <length> | left | center | right ] [
<percentage> | <length> | top | center | bottom ]? |<br>
[ center | [ left | right ] [ <percentage> | <length> ]? ]
&& [ center | [ top | bottom ] [ <percentage> |
<length> ]? ]<br>
<tr>
<td> <em>Initial:</em>
<td> 50% 50%
<tr>
<td> <em>Applies to:</em>
<td> block-level and inline-level elements
<tr>
<td> <em>Inherited:</em>
<td> no
<tr>
<td> <em>Percentages:</em>
<td> refer to the size of the element's border sbox
<tr>
<td> <em>Media:</em>
<td> visual
<tr>
<td> <em>Computed value:</em>
<td> For <length> the absolute value, otherwise a percentage
</table>
<!-- ======================================================================================================= -->
<h2 id=transform-functions><span class=secno>4. </span> The Transformation
Functions</h2>
<p> The value of the <a class=prop-name href="#effects">transform</a>
property is a list of <transform-functions> applied in the order
provided. The individual transform functions are separated by whitespace.
The set of allowed transform functions is given below. In this list the
type <translation-value> is defined as a <length> or
<percentage> value, and the <angle> type is defined by <a
href="http://www.w3.org/TR/css3-values/">CSS Values and Units.</a>
<dl>
<dt> <span class=prop-value>matrix(<number>, <number>,
<number>, <number>, <number>, <number>)</span>
<dd> specifies a 2D transformation in the form of a <a
href="http://www.w3.org/TR/SVG/coords.html#TransformMatrixDefined">transformation
matrix</a> of six values. <span
class=prop-value>matrix(a,b,c,d,e,f)</span> is equivalent to applying the
transformation matrix <strong>[a b c d e f]</strong>.
<dt> <span class=prop-value>translate(<translation-value>[,
<translation-value>])</span>
<dd> specifies a <a
href="http://www.w3.org/TR/SVG/coords.html#TranslationDefined">2D
translation</a> by the vector [tx, ty], where tx is the first
translation-value parameter and ty is the optional second
translation-value parameter. If <em><ty></em> is not provided, ty
has zero as a value.
<dt> <span class=prop-value>translateX(<translation-value>)</span>
<dd> specifies a <a
href="http://www.w3.org/TR/SVG/coords.html#TranslationDefined">translation</a>
by the given amount in the X direction.
<dt> <span class=prop-value>translateY(<translation-value>)</span>
<dd> specifies a <a
href="http://www.w3.org/TR/SVG/coords.html#TranslationDefined">translation</a>
by the given amount in the Y direction.
<dt> <span class=prop-value>scale(<number>[, <number>])</span>
<dd> specifies a <a
href="http://www.w3.org/TR/SVG/coords.html#ScalingDefined">2D scale</a>
operation by the [sx,sy] scaling vector described by the 2 parameters. If
the second parameter is not provided, it is takes a value equal to the
first.
<dt> <span class=prop-value>scaleX(<number>)</span>
<dd> specifies a scale operation using the [sx,1] scaling vector, where sx
is given as the parameter.
<dt> <span class=prop-value>scaleY(<number>)</span>
<dd> specifies a scale operation using the [1,sy] scaling vector, where sy
is given as the parameter.
<dt> <span class=prop-value>rotate(<angle>)</span>
<dd> specifies a <a
href="http://www.w3.org/TR/SVG/coords.html#RotationDefined">2D
rotation</a> by the angle specified in the parameter about the origin of
the element, as defined by the <em><a
href="#transform-origin">transform-origin</a></em> property.
<dt> <span class=prop-value>skewX(<angle>)</span>
<dd> specifies a <a
href="http://www.w3.org/TR/SVG/coords.html#SkewXDefined">skew
transformation along the X axis</a> by the given angle.
<dt> <span class=prop-value>skewY(<angle>)</span>
<dd> specifies a <a
href="http://www.w3.org/TR/SVG/coords.html#SkewYDefined">skew
transformation along the Y axis</a> by the given angle.
<dt> <span class=prop-value>skew(<angle> [, <angle>])</span>
<dd> specifies a <a
href="http://www.w3.org/TR/SVG/coords.html#SkewXDefined">skew
transformation along the X and Y axes</a>. The first angle parameter
specifies the skew on the X axis. The second angle parameter specifies
the skew on the Y axis. If the second parameter is not given then a value
of 0 is used for the Y angle (ie. no skew on the Y axis).
</dl>
<h2 id=transform-values><span class=secno>5. </span> Transform Values and
Lists</h2>
<p> The <translation-value> values are defined as [<percentage>
| <length>]. All other value types are described <a
href="http://www.w3.org/TR/REC-CSS2/syndata.html#values">as CSS types</a>.
If a list of transforms is provided, then the net effect is as if each
transform had been specified separately in the order provided. For
example,
<pre>
<div style="transform:translate(-10px,-20px) scale(2) rotate(45deg) translate(5px,10px)"/>
</pre>
<p> is functionally equivalent to:
<pre>
<div style="transform:translate(-10px,-20px)">
<div style="transform:scale(2)">
<div style="transform:rotate(45deg)">
<div style="transform:translate(5px,10px)">
</div>
</div>
</div>
</div>
</pre>
<div class=example>
<pre>
div {
transform: translate(100px, 100px);
}
</pre>
Move the element by 100 pixels in both the X and Y directions.
<div class=figure> <img alt="The 100px translation in X and Y"
src=transform1.png></div>
</div>
<div class=example>
<pre>
div {
height: 100px; width: 100px;
transform: translate(80px, 80px) scale(1.5, 1.5) rotate(45deg);
}
</pre>
Move the element by 80 pixels in both the X and Y directions, then scale
the element by 150%, then rotate it 45 degrees clockwise about the Z axis.
Note that the scale and rotate operate about the center of the element,
since the element has the default transform-origin of 50% 50%.
<div class=figure> <img alt="The transform specified above"
src="compound_transform.png"></div>
</div>
<!-- ======================================================================================================= -->
<h2 id=animation><span class=secno>6. </span> Transitions and animations
between transform values</h2>
<p> When animating or transitioning the value of a transform property the
rules described below are applied. The ‘<code
class=property>from</code>’ transform is the transform at the start
of the transition or current keyframe. The ‘<code
class=property>end</code>’ transform is the transform at the end of
the transition or current keyframe.
<ul>
<li> If the ‘<code class=property>from</code>’ and
‘<code class=property>to</code>’ transforms are both single
functions of the same type:
<ul>
<li> For translate, translateX, translateY, scale, scaleX, scaleY,
rotate, skew, skewX and skewY functions:
<ul>
<li> the individual components of the function are interpolated
numerically.
</ul>
<li> For matrix:
<ul>
<li> the matrix is decomposed using <a
href="http://tog.acm.org/GraphicsGems/gemsii/unmatrix.c">the method
described by unmatrix</a> into separate translation, scale, rotation
and skew matrices, then each decomposed matrix is interpolated
numerically, and finally combined in order to produce a resulting 3x2
matrix.
</ul>
</ul>
<li> If both the ‘<code class=property>from</code>’ and
‘<code class=property>to</code>’ transforms are "none":
<ul>
<li> There is no interpolation necessary
</ul>
<li> If one of the ‘<code class=property>from</code>’ or
‘<code class=property>to</code>’ transforms is "none":
<ul>
<li> The ‘<code class=property>none</code>’ is replaced by
an equivalent identity function list for the corresponding transform
function list.
<p> For example, if the ‘<code class=property>from</code>’
transform is "scale(2)" and the ‘<code
class=property>to</code>’ transform is "none" then the value
"scale(1)" will be used as the ‘<code
class=property>to</code>’ value, and animation will proceed
using the rule above. Similarly, if the ‘<code
class=property>from</code>’ transform is "none" and the
‘<code class=property>to</code>’ transform is "scale(2)
rotate(50deg)" then the animation will execute as if the ‘<code
class=property>from</code>’ value is "scale(1) rotate(0)".</p>
<p> The identity functions are translate(0), translateX(0),
translateY(0), scale(1), scaleX(1), scaleY(1), rotate(0), rotateX(0),
rotateY(0), skewX(0), skewY(0), skew(0, 0) and matrix(1, 0, 0, 1, 0,
0).</p>
</ul>
<li> If both the ‘<code class=property>from</code>’ and
‘<code class=property>to</code>’ transforms have the same
number of transform functions and corresponding functions in each
transform list are of the same type:
<ul>
<li> Each transform function is animated with its corresponding
destination function in isolation using the rules described above. The
individual values are then applied as a list to produce resulting
transform value.
</ul>
<li> Otherwise:
<ul>
<li> The transform function lists are each converted into the equivalent
matrix value and animation proceeds using the rule for a single
function above.
</ul>
</ul>
<p> In some cases, an animation might cause a transformation matrix to be
singular or non-invertible. For example, an animation in which scale moves
from 1 to -1. At the time when the matrix is in such a state, the
transformed element is not rendered.
<h2 id=matrix-decomposition><span class=secno>7. </span> Matrix
decomposition for animation</h2>
<p> When interpolating between 2 matrices, each is decomposed into the
corresponding translation, rotation, scale, skew, and perspective values.
Not all matrices can be accurately described by these values. Those that
can't are decomposed into the most accurate representation possible, using
the technique below. This technique is taken from The "unmatrix" method in
"Graphics Gems II, edited by Jim Arvo". The pseudocode below works on a
4x4 homogeneous matrix. A 3x2 2D matrix is therefore first converted to
4x4 homogeneous form.
<h3 id=d-matrix-to-4x4-matrix-conversion><span class=secno>7.1. </span>2D
matrix to 4x4 matrix conversion</h3>
<pre>
Input: matrix2d ; a 3x2 transformation matrix
; rotation matrix in m11,m12,m21,m22
; x,y translation in m31,m32
Output: matrix ; a 4x4 homgeneous matrix
matrix[0][0] = matrix2d[0][0]
matrix[0][1] = matrix2d[0][1]
matrix[0][2] = 0
matrix[0][3] = 0
matrix[1][0] = matrix2d[1][0]
matrix[1][1] = matrix2d[1][1]
matrix[1][2] = 0
matrix[1][3] = 0
matrix[2][0] = 0
matrix[2][1] = 0
matrix[2][2] = 1
matrix[2][3] = 0
matrix[3][0] = matrix2d[2][0]
matrix[3][1] = matrix2d[2][1]
matrix[3][2] = 0
matrix[3][3] = 1
return matrix
</pre>
<h3 id=unmatrix><span class=secno>7.2. </span>Unmatrix</h3>
<pre>
Input: matrix ; a 4x4 matrix
Output: translate ; a 3 component vector
rotate ; Euler angles, represented as a 3 component vector
scale ; a 3 component vector
skew ; skew factors XY,XZ,YZ represented as a 3 component vector
perspective ; a 4 component vector
Returns false if the matrix cannot be decomposed, true if it can
Supporting functions (point is a 3 component vector, matrix is a 4x4 matrix):
float determinant(matrix) returns the 4x4 determinant of the matrix
matrix inverse(matrix) returns the inverse of the passed matrix
matrix transpose(matrix) returns the transpose of the passed matrix
point multVecMatrix(point, matrix) multiplies the passed point by the passed matrix
and returns the transformed point
float length(point) returns the length of the passed vector
point normalize(point) normalizes the length of the passed point to 1
float dot(point, point) returns the dot product of the passed points
float cos(float) returns the cosine of the passed angle in radians
float asin(float) returns the arcsine in radians of the passed value
float atan2(float y, float x) returns the principal value of the arc tangent of
y/x, using the signs of both arguments to determine
the quadrant of the return value
Decomposition also makes use of the following function:
point combine(point a, point b, float ascl, float bscl)
result[0] = (ascl * a[0]) + (bscl * b[0])
result[1] = (ascl * a[1]) + (bscl * b[1])
result[2] = (ascl * a[2]) + (bscl * b[2])
return result
// Normalize the matrix.
if (matrix[3][3] == 0)
return false
for (i = 0; i < 4; i++)
for (j = 0; j < 4; j++)
matrix[i][j] /= matrix[3][3]
// perspectiveMatrix is used to solve for perspective, but it also provides
// an easy way to test for singularity of the upper 3x3 component.
perspectiveMatrix = matrix
for (i = 0; i < 3; i++)
perspectiveMatrix[i][3] = 0
perspectiveMatrix[3][3] = 1
if (determinant(perspectiveMatrix) == 0)
return false
// First, isolate perspective.
if (matrix[0][3] != 0 || matrix[1][3] != 0 || matrix[2][3] != 0)
// rightHandSide is the right hand side of the equation.
rightHandSide[0] = matrix[0][3];
rightHandSide[1] = matrix[1][3];
rightHandSide[2] = matrix[2][3];
rightHandSide[3] = matrix[3][3];
// Solve the equation by inverting perspectiveMatrix and multiplying
// rightHandSide by the inverse.
inversePerspectiveMatrix = inverse(perspectiveMatrix)
transposedInversePerspectiveMatrix = transposeMatrix4(inversePerspectiveMatrix)
perspective = multVecMatrix(rightHandSide, transposedInversePerspectiveMatrix)
// Clear the perspective partition
matrix[0][3] = matrix[1][3] = matrix[2][3] = 0
matrix[3][3] = 1
else
// No perspective.
perspective[0] = perspective[1] = perspective[2] = 0
perspective[3] = 1
// Next take care of translation
translate[0] = matrix[3][0]
matrix[3][0] = 0
translate[1] = matrix[3][1]
matrix[3][1] = 0
translate[2] = matrix[3][2]
matrix[3][2] = 0
// Now get scale and shear. 'row' is a 3 element array of 3 component vectors
for (i = 0; i < 3; i++)
row[i][0] = matrix[i][0]
row[i][1] = matrix[i][1]
row[i][2] = matrix[i][2]
// Compute X scale factor and normalize first row.
scale[0] = length(row[0])
row[0] = normalize(row[0])
// Compute XY shear factor and make 2nd row orthogonal to 1st.
skew[0] = dot(row[0], row[1])
row[1] = combine(row[1], row[0], 1.0, -skew[0])
// Now, compute Y scale and normalize 2nd row.
scale[1] = length(row[1])
row[1] = normalize(row[1])
skew[0] /= scale[1];
// Compute XZ and YZ shears, make 3rd row orthogonal
skew[1] = dot(row[0], row[2])
row[2] = combine(row[2], row[0], 1.0, -skew[1])
skew[2] = dot(row[1], row[2])
row[2] = combine(row[2], row[1], 1.0, -skew[2])
// Next, get Z scale and normalize 3rd row.
scale[2] = length(row[2])
row[2] = normalize(row[2])
skew[1] /= scale[2]
skew[2] /= scale[2]
// At this point, the matrix (in rows) is orthonormal.
// Check for a coordinate system flip. If the determinant
// is -1, then negate the matrix and the scaling factors.
pdum3 = cross(row[1], row[2])
if (dot(row[0], pdum3) < 0)
for (i = 0; i < 3; i++) {
scale[0] *= -1;
row[i][0] *= -1
row[i][1] *= -1
row[i][2] *= -1
// Now, get the rotations out
rotate[1] = asin(-row[0][2]);
if (cos(rotate[1]) != 0)
rotate[0] = atan2(row[1][2], row[2][2]);
rotate[2] = atan2(row[0][1], row[0][0]);
else
rotate[0] = atan2(-row[2][0], row[1][1]);
rotate[2] = 0;
return true;</pre>
<h3 id=animating-the-components><span class=secno>7.3. </span>Animating the
components</h3>
<p> Once decomposed, each component of each returned value of the source
matrix is linearly interpolated with the corresponding component of the
destination matrix. For instance, the translate[0], translate[1] and
translate[2] values are interpolated numerically, and the result is used
to set the translation of the animating element.
<h3 id=recomposing-the-matrix><span class=secno>7.4. </span>Recomposing the
matrix</h3>
<p><em>This section is not normative.</em>
<p> After interpolation the resulting values are used to position the
element. One way to use these values is to recompose them into a 4x4
matrix. This can be done using the Transformation Functions of the <em><a
href="#effects">transform</a></em> property. The following JavaScript
example produces a string for this purpose. The values passed in are the
output of the Unmatrix function above:
<pre>
function compose(translate, rotate, scale, skew, perspective, elementID)
{
var s = "matrix3d(1,0,0,0, 0,1,0,0, 0,0,1,0, " +
perspective[0] + ", " + perspective[1] + ", " +
perspective[2] + ", " + perspective[3] + ")";
s += " translate3d(" + translate[0] + ", " + translate[1] + ", " + translate[2] + ")";
s += " rotateX(" + rotate[0] + ")";
s += " rotateY(" + rotate[0] + ")";
s += " rotateZ(" + rotate[0] + ")";
s += " matrix3d(1,0,0,0, 0,1,0,0, 0," + skew[2] + ",1,0, 0,0,0,1)";
s += " matrix3d(1,0,0,0, 0,1,0,0, " + skew[1] + ",0,1,0, 0,0,0,1)";
s += " matrix3d(1,0,0,0, " + skew[0] + ",1,0,0, 0,0,1,0, 0,0,0,1)";
s += " scale3d(" + scale[0] + ", " + scale[1] + ", " + scale[2] + ")";
document.getElementById(elementID).style.transform = s;
}</pre>
<h2 id=dom-interfaces><span class=secno>8. </span> DOM Interfaces</h2>
<p> This section describes the interfaces and functionality added to the
DOM to support runtime access to the functionality described above.
<h3 id=cssmatrix-interface><span class=secno>8.1. </span> CSSMatrix</h3>
<dl>
<dt> <b>Interface <i><a id=DOM-CSSMatrix
name=DOM-CSSMatrix>CSSMatrix</a></i></b>
<dd>
<p> The <code>CSSMatrix</code> interface represents a 4x4 homogeneous
matrix.</p>
<dl>
<dt> <b>IDL Definition</b>
<dd>
<div class=idl-code>
<pre>
interface CSSMatrix {
attribute float a;
attribute float b;
attribute float c;
attribute float d;
attribute float e;
attribute float f;
void setMatrixValue(in DOMString string) raises(DOMException);
CSSMatrix multiply(in CSSMatrix secondMatrix);
CSSMatrix multiplyLeft(in CSSMatrix secondMatrix);
CSSMatrix inverse() raises(DOMException);
CSSMatrix translate(in float x, in float y);
CSSMatrix scale(in float scaleX, in float scaleY);
CSSMatrix skew(in float angleX, in float angleY);
CSSMatrix rotate(in float angle);
};</pre>
</div>
<br>
</dd>
<!-- IDL -->
<dt> <b>Attributes</b>
<dd>
<dl>
<dt> <code class=attribute-name><a id=DOM-CSSMatrix-matrix
name=DOM-CSSMatrix-matrix>a-f</a></code> of type <code>float</code>
<dd> Each of these attributes represents one of the values in the 3x2
matrix.<br>
</dl>
</dd>
<!-- Attributes -->
<dt> <b>Methods</b>
<dd>
<dl><!-- ===================================================== -->
<dt> <code class=method-name><a id=DOM-CSSMatrix-setMatrixValue
name=DOM-CSSMatrix-setMatrixValue>setMatrixValue</a></code>
<dd>
<div class=method> The <code>setMatrixValue</code> method replaces
the existing matrix with one computed from parsing the passed string
as though it had been assigned to the transform property in a CSS
style rule.
<div class=parameters> <b>Parameters</b>
<div class=paramtable>
<dl>
<dt> <code class=parameter-name>string</code> of type
<code>DOMString</code>
<dd> The string to parse.<br>
</dl>
</div>
</div>
<!-- parameters -->
<div class=return-value> <b>No Return Value</b></div>
<div> <b>Exceptions</b>
<div class=returnvalue>
<dl>
<dt> <code>DOMException SYNTAX_ERR</code>
<dd> Thrown when the provided string can not be parsed into a
CSSMatrix.
</dl>
</div>
</div>
</div>
</dd>
<!-- setMatrixValue -->
<!-- ===================================================== -->
<dt> <code class=method-name><a id=DOM-CSSMatrix-multiply
name=DOM-CSSMatrix-multiply>multiply</a></code>
<dd>
<div class=method> The <code>multiply</code> method returns a new
CSSMatrix which is the result of this matrix multiplied by the
passed matrix, with the passed matrix to the right. This matrix is
not modified.
<div class=parameters> <b>Parameters</b>
<div class=paramtable>
<dl>
<dt> <code class=parameter-name>secondMatrix</code> of type
<code>CSSMatrix</code>
<dd> The matrix to multiply.<br>
</dl>
</div>
</div>
<!-- parameters -->
<div class=return-value> <b>Return Value</b>
<div class=returnvalue>
<dl>
<dt> <code>CSSMatrix</code>
<dd> The result matrix.<br>
</dl>
</div>
</div>
<div> <b>No Exceptions</b></div>
</div>
</dd>
<!-- multiply() -->
<!-- ===================================================== -->
<dt> <code class=method-name><a id=DOM-CSSMatrix-multiplyLeft
name=DOM-CSSMatrix-multiplyLeft>multiplyLeft</a></code>
<dd>
<div class=method> The <code>multiplyLeft</code> method returns a new
CSSMatrix which is the result of this matrix multiplied by the
passed matrix, with the passed matrix to the left. This matrix is
not modified.
<div class=parameters> <b>Parameters</b>
<div class=paramtable>
<dl>