-
Notifications
You must be signed in to change notification settings - Fork 707
/
Copy pathOverview.bs
627 lines (531 loc) · 21.3 KB
/
Overview.bs
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
<style type="text/css">
table.play-state-transitions {
empty-cells: hide;
border-spacing: 0px;
}
table.play-state-transitions td {
padding: 0.2em 1em;
border: 1px solid black;
}
table.play-state-transitions th {
text-align: center;
}
table.play-state-transitions th.rowgroup {
transform: rotate(-180deg);
writing-mode: vertical-lr;
padding-left: 5px;
}
table.event-state-transitions {
width: 100%;
border-spacing: 0px;
border-collapse: collapse;
}
table.event-state-transitions th:first-child {
width: 30%;
}
table.event-state-transitions th {
text-align: center;
}
table.event-state-transitions td {
padding: 0.2em 1em;
border: 1px solid black;
}
</style>
<pre class='metadata'>
Title: CSS Animations Level 2
Status: ED
Work Status: Exploring
Shortname: css-animations-2
Level: 2
Group: csswg
ED: https://drafts.csswg.org/css-animations-2/
Editor: L. David Baron, Mozilla https://www.mozilla.org/, https://dbaron.org/, w3cid 15393
Editor: Brian Birtles, Mozilla https://www.mozilla.org/, bbirtles@mozilla.com, w3cid 43194
!Issues List: <a href="https://www.w3.org/Bugs/Public/buglist.cgi?component=Animations&list_id=36653&product=CSS&query_format=advanced&resolution=---">In Bugzilla</a>
Abstract: This CSS module describes a way for authors to animate the values of CSS properties over time, using keyframes. The behavior of these keyframe animations can be controlled by specifying their duration, number of repeats, and repeating behavior.
Ignored Vars: auto-rewind
</pre>
<pre class="anchors">
urlPrefix: https://w3c.github.io/web-animations/; type: interface; spec: web-animations
text: Animation
text: KeyframeEffectReadOnly
urlPrefix: https://w3c.github.io/web-animations/; type: method; for: Animation; spec: web-animations
text: play()
text: pause()
urlPrefix: https://w3c.github.io/web-animations/; type: method; for: KeyframeEffectReadOnly; spec: web-animations
text: getFrames()
urlPrefix: https://w3c.github.io/web-animations/; type: dfn; spec: web-animations
text: active duration
text: active phase
text: active time
text: after phase
text: animation
text: animation class
text: animation effect
text: animation playback rate
text: before phase
text: composite operation
text: current iteration
text: current time
text: fill mode
text: global animation list
text: idle play state
text: idle phase
text: iteration duration
text: iteration start
text: pause an animation
text: pending play state
text: play an animation
text: sampling
text: start delay
text: target element
text: target effect
text: target effect end
text: unresolved
</pre>
<h2 id="delta">Delta specification</h2>
<p>This is a delta specification, meaning that it currently contains
only the differences from CSS Animations Level 1 [[!CSS3-ANIMATIONS]].
Once the Level 1 specification is closer to complete, it will be merged
with the additions here into a complete level 2 specification.</p>
# Animations # {#animations}
## Owning element ## {#owning-element-section}
The <dfn>owning element</dfn> of an animation refers to the element or
pseudo-element to which the 'animation-name' property was applied that generated
the animation.
If an animation was generated directly by script (e.g. using
the {{CSSAnimation}} constructor) then it has no <a>owning element</a>.
If an animation generated using the markup defined in this specification is
later disassociated from that markup by an update to the computed value of the
'animation-name' property on the <a>owning element</a>, the animation is
disassociated from its <a>owning element</a> (that is, it has no <a>owning
element</a> from that point forwards).
<div class="note">
In the example below, <code>animation</code>'s initial <a>owning element</a>
is <code>elem</code>. <code>animation</code> is disassociated from
<code>element</code> through an update to the computed value of
<code>elem</code>'s 'animation-name' property.
<pre class="example lang-javascript">
elem.style.animation = 'spin 1s';
let animation = elem.getAnimations()[0]; // animation's owning element is elem
elem.style.animation = ''; // animation no longer has an owning element
</pre>
Note that although the <a>owning element</a> is often equal to the <a>target
element</a> of an animation's <a>target effect</a>, this is not always the case.
The following example demonstrates some of the situations where these two
elements may differ.
<pre class="example lang-javascript">
elem.style.animation = 'move 1s';
let animation = elem.getAnimations()[0];
// animation.effect.target == elem == animation's owning element
let mutableEffect = animation.effect.clone();
animation.effect = mutableEffect;
animation.effect.target = elem2;
// animation.effect.target == elem2 != animation's owning element
animation.effect = null;
// animation.effect.target is undefined != animation's owning element
</pre>
</div>
## Animation composite order ## {#animation-composite-order}
<a spec='web-animations'>Animations</a> generated from the markup or interfaces
(e.g. the {{CSSAnimation}} constructor) defined in this specification have an
<a>animation class</a> of ‘CSS Animation’.
CSS Animations <em>with</em> an <a>owning element</a> have a <em>later</em>
composite order than CSS Transitions but an <em>earlier</em> composite order
than animations without a specific <a>animation class</a>.
Within the set of CSS Animations <em>with</em> an <a>owning element</a>, two
animations <var>A</var> and <var>B</var> are sorted in composite order (first to
last) as follows:
1. If the <a>owning element</a> of <var>A</var> and <var>B</var>
differs, sort <var>A</var> and <var>B</var> by <a>tree order</a>
of their corresponding <a>owning elements</a>.
With regard to pseudo-elements, the sort order is as follows:
* element
* ::before
* ::after
* element children
1. Otherwise, sort <var>A</var> and <var>B</var> based on their position in the
computed value of the 'animation-name' property of the (common) <a>owning
element</a>.
The composite order of CSS Animations <em>without</em> an <a>owning element</a>
is based on their position in the <a>global animation list</a>.
Issue: This differs from the behavior defined for transitions. We should
probably sort transitions first, then animation, then use the global animation
list. The reason being that when developer tools etc. hang on to orphaned
animations and transitions in order to replay them, they should maintain
roughly the same composite order.
CSS Animations generated using the markup defined in this specification are
<em>not</em> added to the <a>global animation list</a> when they are created.
Instead, these animations are appended to the <a>global animation list</a> at
the first moment when they transition out of the <a>idle play state</a> after
being disassociated from their <a>owning element</a>.
CSS Animations that have been disassociated from their <a>owning element</a>
but are still <a lt="idle play state">idle</a> do not have a defined
composite order.
Note, this behavior relies on the fact that disassociating an animation
from its <a>owning element</a> always causes it to enter (or remain) in the
<a>idle play state</a>.
CSS Animations created using the {{CSSAnimation}} constructor are appended
to the <a>global animation list</a> at the moment they are constructed.
# Keyframes # {#keyframes}
## The 'animation-play-state' property ## {#animation-play-state}
### Interaction between 'animation-play-state' and the Web Animations API ### {#interaction-between-animation-play-state-and-web-animations-API}
Both this specification and the Web Animations specification [[WEB-ANIMATIONS]]
define mechanisms for pause control, specifically the 'animation-play-state'
property, and the {{Animation/play()}} and {{Animation/pause()}} methods
respectively.
<div class="note">
The interaction of these methods can be summarized as follows:
* Calling {{Animation/pause()}} is sticky. The animation will remain paused
until there is a subsequent call to {{Animation/play()}} after which point
the animation will begin tracking changes to the computed value of the
'animation-play-state' property on the <a>owning element</a> from the next
moment it becomes newly ''paused''.
* If the computed 'animation-play-state' on the <a>owning element</a> is
''paused'', calling {{Animation/play()}} will temporarily override the
'animation-play-state' until it next becomes ''running''.
</div>
With regards to the pausing, an animation can be considered to be in one of
five mutually-exclusive states:
<ul style="list-style-type: upper-latin">
<li>Running
<li>Running and temporarily overriding 'animation-play-state': ''paused''
<li>Paused and sticky overriding 'animation-play-state': ''running''
<li>Paused and sticky overriding 'animation-play-state': ''paused''
<li>Paused by 'animation-play-state'
</ul>
A state transition chart follows:
<table class="play-state-transitions">
<tr>
<td rowspan="2"></td>
<td></td>
<th colspan="5">Initial state</th>
</tr>
<tr>
<th>Event</th>
<th>A</th>
<th>B</th>
<th>C</th>
<th>D</th>
<th>E</th>
</tr>
<tr>
<th rowspan="4" class="rowgroup">Resulting state</th>
<td>{{Animation/play()}}</td>
<td>A</td>
<td>B</td>
<td>A</td>
<td>B</td>
<td>B</td>
</tr>
<tr>
<td>{{Animation/pause()}}</td>
<td>C</td>
<td>D</td>
<td>C</td>
<td>D</td>
<td>D</td>
</tr>
<tr>
<td>'animation-play-state' → ''running''</td>
<td>A</td>
<td>A</td>
<td>C</td>
<td>C</td>
<td>A</td>
</tr>
<tr>
<td>'animation-play-state' → ''paused''</td>
<td>E</td>
<td>B</td>
<td>D</td>
<td>D</td>
<td>E</td>
</tr>
</table>
If any change causes an animation to change from one of the running states (A,
B) to one of the paused states (C, D, E), the user agent must run the <a>pause
an animation</a> procedure on the animation.
Likewise, for any change from one of the the paused states to one of the
running states, the user agent must run the <a>play an animation</a> procedure
on the animation. If the change is due to a change in the computed value of
'animation-play-state' (i.e. the transition E → A) the
<var>auto-rewind</var> flag for that procedure must be set to false; otherwise
it must be set to true.
</div>
## The 'animation-composition' property ## {#animation-composition}
The 'animation-composition' property defines the <a>composite operation</a>
used when multiple animations affect the same property simultaneously.
<pre class='propdef'>
Name: animation-composition
Value: <<single-animation-composition>>#
Initial: replace
Applies to: all elements
Inherited: none
Percentages: N/A
Computed value: list, each item a keyword as specified
Animation type: not animatable
Canonical order: per grammar
</pre>
<dfn><single-animation-composition></dfn> = replace | add | accumulate
The values of 'animation-composition' have the meaning defined for the
corresponding values of the <a>composite operation</a> defined in Web
Animations [[!WEB-ANIMATIONS]].
When specified in a keyframe, 'animation-composition' defines the composite
operation to use for each property specified in that keyframe until the next
keyframe specifying each property.
<div class='example'>
For example, the following stylesheet defines two different animations
targetting the 'scale' property.
<pre>
@keyframes heartbeat {
from {
scale: 1;
animation-timing-function: ease-out;
}
30% {
scale: 1.3;
}
}
.heartbeat {
animation: heartbeat 0.3s 2s infinite;
}
@keyframes throb {
50% {
scale: 1.8;
}
}
.icon:mouseover {
animation: throb 0.4s add;
}
</pre>
If these two animations are applied to the same element, normally only
one animation would apply, but by specifying ''add'' as the
'animation-composition' on the second animation, the result of the two
animations will be combined.
Since CSS Transitions [[CSS3-TRANSITIONS]] have a lower composite
order, it is possible to use 'animation-composition' to combine CSS
Animations with underlying transitions as in the following example.
<pre>
.icon {
filter: blur(20px);
transition: filter 0.5s;
}
.icon:hover {
filter: blur(0px);
animation: brightness-pulse 3s infinite add;
}
@keyframes pulse {
0% {
scale: 1.1;
filter: brightness(130%);
}
10% {
scale: 1;
filter: brightness(100%);
}
}
</pre>
Issue: Create pictures of these examples and verify they make sense.
</div>
# Animation Events # {#events}
## Event dispatch ## {#event-dispatch}
Note, this is a more general description of event dispatch than that of CSS
Animations Level 1 [[CSS3-ANIMATIONS]] since it must account for the
possibility of animations being seeked or reversed using the Web Animations API
[[WEB-ANIMATIONS]].
For the purpose of determining which events to dispatch, the
[[web-animations#animation-effect-phases-and-states|phases]] defined in
the Web Animations model are used. These definitions apply to an <a>animation
effect</a>, however, for the purpose of dispatching events, we consider a
CSS Animation to have the same phase as its <a>target effect</a>. For example,
a CSS Animation is in the <a>before phase</a> if its <a>target effect</a>
is in the <a>before phase</a>.
A CSS Animation that does not have a <a>target effect</a> is considered to be in
the <a>idle phase</a> if its <a>current time</a> is <a>unresolved</a>, in the
<a>before phase</a> if its <a>current time</a> is less than zero, and in the
<a>after phase</a> otherwise.
Similarly, subsequent references to the <a>start delay</a>, <a>active
duration</a>, <a>current iteration</a>, <a>iteration start</a>, and
<a>iteration duration</a> of a CSS animation should be understood to refer
to the corresponding properties of the animation's <a>target effect</a>.
For calculating the {{AnimationEvent/elapsedTime}} of each event, the following
definitions are used:
* <dfn>interval start</dfn> =
<code>max(min(-<a>start delay</a>, <a>active duration</a>), 0)</code>
* <dfn>interval end</dfn> =
<code>max(min(<a>target effect end</a> - <a>start delay</a>,
<a>active duration</a>), 0)</code>
Each time an animation is <a lt="sampling">sampled</a> and is <em>not</em> <a
lt="pending play state">pending</a>, the events to dispatch are determined by
comparing the animation's phase before and after the sample as follows:
<table class="event-state-transitions">
<thead>
<tr>
<th>Change</th>
<th>Events dispatched</th>
<th><dfn>Elapsed time</dfn> (ms)</th>
</tr>
</thead>
<tbody>
<tr>
<td><a lt="idle phase">idle</a> or <a lt="before phase">before</a> →
<a lt="active phase">active</a></td>
<td>{{animationstart}}</td>
<td><a>interval start</a>
</td>
</tr>
<tr>
<td rowspan="2">
<a lt="idle phase">idle</a> or <a lt="before phase">before</a> →
<a lt="after phase">after</a> <a
href="#multiple-events-note">٭</a></td>
<td>{{animationstart}}</td>
<td><a>interval start</a>
</td>
</tr>
<tr>
<td>{{animationend}}</td>
<td><a>interval end</a>
</td>
</tr>
<tr>
<td><a lt="active phase">active</a> →
<a lt="before phase">before</a></td>
<td>{{animationend}}</td>
<td><a>interval start</a></td>
</tr>
<tr>
<td><a lt="active phase">active</a> →
<a lt="active phase">active</a>
<em>and</em>
the <a>current iteration</a> of the animation's <a>target effect</a>
has changed since the previous sample
</td>
<td>{{animationiteration}}</td>
<td>(See below)
<a href="#animation-iteration-elapsed-time">†</a></td>
</tr>
<tr>
<td><a lt="active phase">active</a> →
<a lt="after phase">after</a></td>
<td>{{animationend}}</td>
<td><a>interval end</a></td>
</tr>
<tr>
<td><a lt="after phase">after</a> →
<a lt="active phase">active</a></td>
<td>{{animationstart}}</td>
<td><a>interval end</a></td>
</tr>
<tr>
<td rowspan="2"><a lt="after phase">after</a> →
<a lt="before phase">before</a> <a
href="#multiple-events-note">٭</a></td>
<td>{{animationstart}}</td>
<td><a>interval end</a></td>
</tr>
<tr>
<td>{{animationend}}</td>
<td><a>interval start</a></td>
</tr>
<tr>
<td><em>not</em> <a lt="idle phase">idle</a> and <em>not</em>
<a lt="after phase">after</a>→
<a lt="idle phase">idle</a></td>
<td>{{animationcancel}}</td>
<td>The <a>active time</a> of the animation at the moment it was cancelled
calculated using a <a>fill mode</a> of both.</td>
</tr>
</tbody>
</table>
<p id="multiple-events-note">٭ Where multiple events are listed for
a state change, all events are dispatched in the order listed and in immediate
succession.</p>
<p id="animation-iteration-elapsed-time">† The <a>elapsed time</a> for
an {{animationiteration}} event is defined as follows:</p>
1. Let <var>previous current iteration</var> be the <a>current iteration</a>
from the previous sample.
1. If <var>previous current iteration</var> is greater than <a>current
iteration</a>, let <var>iteration boundary</var> be <code><a>current
iteration</a> + 1</code>, otherwise let it be <a>current iteration</a>.
1. The <a>elapsed time</a> is the result of evaluating
<code>(<var>iteration boundary</var> - <a>iteration start</a>) ×
<a>iteration duration</a>)</code>.
Since the <a>elapsed time</a> defined in the table and procedure above is
expressed in milliseconds, it must be divided by 1,000 to produce a value in
seconds before being assigned to the {{AnimationEvent/elapsedTime}} member of
the {{AnimationEvent}}.
# DOM Interfaces # {#interface-dom}
## The CSSAnimation interface ## {#the-CSSAnimation-interface}
<pre class="idl">
[Exposed=Window]
interface CSSAnimation : Animation {
readonly attribute CSSOMString animationName;
};
</pre>
: <dfn attribute for=CSSAnimation>animationName</dfn>
:: The key used to find matching keyframes rules that define <a>target
effect</a> at the point when the animation was created.
This is the value of the 'animation-name' property that caused this
object to be generated or, if this object was generated using the
programming interface, the <code>animationName</code> argument
that was passed to the {{CSSAnimation}} constructor.
<div class="issue">
We need to define a constructor for {{CSSAnimation}}.
Perhaps something like the following:
<pre class="idl">
[Constructor (Animatable? target,
CSSOMString animationName,
optional (unrestricted double or KeyframeEffectOptions) options,
optional CSSOMString defaultEasing = "ease"),
Constructor (Animatable? target,
CSSOMString animationName,
(unrestricted double or KeyframeEffectOptions) options,
CSSOMString defaultEasing,
AnimationTimeline? timeline)]
partial interface CSSAnimation { };
</pre>
The difficulty is with liveness. The most useful and least magical
(but most complicated) approach is to define a subclass of
{{KeyframeEffectReadOnly}} that has the special behavior of tracking changes
to all @keyframes rules that match the supplied name and automatically
updating the set of keyframes returned by
{{KeyframeEffectReadOnly/getFrames()}} after filling-in the default easing.
Something like,
<pre class="idl">
[Exposed=Window,
Constructor (CSSOMString keyframesName, CSSOMString defaultEasing)]
interface CSSKeyframeEffectReadOnly : KeyframeEffectReadOnly {
readonly attribute CSSOMString keyframesName;
readonly attribute CSSOMString defaultEasing;
};
</pre>
</div>
## Requirements on pending style changes ## {#requirements-on-pending-style-changes}
Various operations may affect the <a lt="computed value">computed values</a> of
properties on elements. User agents may, as an optimization, defer recomputing
these values until it becomes necessary.
However, all operations included in programming interface defined in this
specification, as well as those operations defined in Web Animations
[[!WEB-ANIMATIONS]] that may return objects defined by this specification,
must produce a result consistent with having fully processed any such pending
changes to computed values.
<div class="note">
As an example, in the following code fragment, when the specified style of
<code>elem</code> is initially updated, a user agent may defer recalculating
the computed value of the 'animation' property.
However, the {{Animatable/getAnimations()}} method called on <code>elem</code>
is specified by Web Animations and can return {{CSSAnimation}} objects as
defined in this specification.
Hence, as result of the requirements in this section, the user agent must
calculate the updated value of <code>elem</code>'s 'animation' property and
create the requested {{CSSAnimation}} object before returning its result.
<div><pre class="example lang-javascript">
elem.style.animation = 'fadeOut 1s';
elem.getAnimations()[0].pause();
</pre></div>
</div>
<h2 id="priv-sec">
Privacy and Security Considerations</h2>
This specification introduces no new privacy or security considerations.