-
Notifications
You must be signed in to change notification settings - Fork 708
/
Copy pathOverview.bs
507 lines (420 loc) · 17.9 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
<h1>CSS Animations Level 2</h1>
<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.rowgroup {
transform: rotate(-180deg);
writing-mode: vertical-lr;
padding-left: 5px;
}
</style>
<pre class='metadata'>
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, dbaron@dbaron.org
!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: animation
text: animation playback rate
text: animation class
text: composite operation
text: current iteration
text: current time
text: global animation list
text: idle play state
text: pause an animation
text: play an animation
text: sampling
text: start delay
text: target element
text: target effect
text: target effect end
</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, ::before and ::after pseudo-elements
Inherited: none
Animatable: no
Percentages: N/A
Media: interactive
Computed value: As specified
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}
## Types of <code>AnimationEvent</code> ## {#event-animationevent}
The <em>additional</em> types of animation events that can occur are:
<dl dfn-type=event dfn-for=animationevent>
<dt><dfn>animationcancel</dfn>
<dd>
The <a idl>animationcancel</a> event occurs when the animation stops running in a way that does not fire an <a idl>animationend</a> event, such as a change in the 'animation-name' that removes the animation, or the animating element or one of its ancestors becoming ''display:none''.
<ul>
<li>Bubbles: Yes</li>
<li>Cancelable: No</li>
<li>Context Info: animationName, elapsedTime, pseudoElement</li>
</ul>
</dl>
## 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 using the Web Animations API
[[WEB-ANIMATIONS]].
For the purpose of determining which events to dispatch, an animation can
be considered to be in one of four mutually-exclusive <dfn
lt="event state">event states</dfn> determined using the following procedure:
1. If the animation is <a lt="idle play state">idle</a> or has no <a>target
effect</a> it is <dfn>idle</dfn>.
1. Otherwise, if the animation has a <a>current time</a> less than the
<a>start delay</a> of its <a>target effect</a>, or, if the animation's
<a lt="animation playback rate">playback rate</a> is less than zero and
it has a <a>current time</a> less than <em>or equal</em> to the
<a>start delay</a> of its <a>target effect</a>, it is
<dfn>left-active</dfn>.
1. Otherwise, if the animation has a <a>current time</a> greater than its
<a>target effect end</a>, or, if the animation's
<a lt="animation playback rate">playback rate</a> is greater than or equal
to zero and it has a <a>current time</a> greater than <em>or equal</em> to
its <a>target effect end</a>, it is <dfn>right-active</dfn>.
1. Otherwise, it is <dfn>active</dfn>.
Each time the animation is <a lt="sampling">sampled</a>, the events to
dispatch are determined by comparing the <a>event state</a> before and
after the sample as follows:
: not <a>active</a> → <a>active</a>
:: <a idl>animationstart</a>
: <a>left-active</a> → <a>right-active</a>
: <a>right-active</a> → <a>left-active</a>
:: <a idl>animationstart</a>, <a idl>animationend</a>
: <a>active</a> → <a>left-active</a>
: <a>active</a> → <a>right-active</a>
:: <a idl>animationend</a>
: <a>active</a> → <a>active</a>
:: <a idl>animationiteration</a> <em>if</em> there has been a change to the
<a>current iteration</a> of the animation's <a>target effect</a>.
: not <a>idle</a> → <a>idle</a>
:: <a idl>animationcancel</a>
Issue: Define the value of <code>elapsedTime</code> for each case.
# DOM Interfaces # {#interface-dom}
## The CSSAnimation interface ## {#the-CSSAnimation-interface}
<pre class="idl">
interface CSSAnimation : Animation {
readonly attribute DOMString 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 <a idl>CSSAnimation</a>.
Perhaps something like the following:
<pre class="idl">
[Constructor (Animatable? target,
DOMString animationName,
optional (unrestricted double or KeyframeEffectOptions) options,
optional DOMString defaultEasing = "ease"),
Constructor (Animatable? target,
DOMString animationName,
(unrestricted double or KeyframeEffectOptions) options,
DOMString 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">
[Constructor (DOMString keyframesName, DOMString defaultEasing)]
interface CSSKeyframeEffectReadOnly : KeyframeEffectReadOnly {
readonly attribute DOMString keyframesName;
readonly attribute DOMString 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>