Fri, 11 Jan 2013 12:52:21 -0800
[css3-animations] Empty keyframe rules are exexecuted as long as duration > 0 (bug 15251)
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <title>CSS Animations</title>
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
6 <link rel="stylesheet" type="text/css" href="../default.css">
7 <link rel="stylesheet" type="text/css" href="http://www.w3.org/StyleSheets/TR/W3C-ED.css">
8 <style type="text/css">
9 div.prod { margin: 1em 2em; }
10 </style>
11 </head>
13 <body>
15 <div class="head">
16 <!--logo-->
18 <h1>CSS Animations</h1>
20 <h2 class="no-num no-toc">[LONGSTATUS] [DATE]</h2>
21 <dl>
22 <dt>This version:
23 <dd><a href="[VERSION]">http://dev.w3.org/csswg/css3-animations/</a>
24 <!--http://www.w3.org/TR/[YEAR]/WD-[SHORTNAME]-[CDATE]/-->
25 <dt>Latest version:
26 <dd><a
27 href="http://www.w3.org/TR/css3-animations/">[LATEST]</a>
28 <dt>Editor's draft:
29 <dd><a href="http://dev.w3.org/csswg/[SHORTNAME]/">http://dev.w3.org/csswg/[SHORTNAME]/</a>
31 <dt>Previous version:
32 <dd><a href="http://www.w3.org/TR/2012/WD-css3-animations-20120403/">
33 http://www.w3.org/TR/2012/WD-css3-animations-20120403/</a>
34 <dt id="editors-list">Editors:
35 <dd><a href="mailto:dino@apple.com">Dean Jackson</a> (<a
36 href="http://www.apple.com/">Apple Inc</a>)
37 <dd><a href="mailto:hyatt@apple.com">David Hyatt</a> (<a
38 href="http://www.apple.com/">Apple Inc</a>)
39 <dd><a href="mailto:cmarrin@apple.com">Chris Marrin</a> (<a
40 href="http://www.apple.com/">Apple Inc</a>)
41 <dd><a href="mailto:sylvaing@microsoft.com">Sylvain Galineau</a>
42 (<a class=org href="http://www.microsoft.com/">Microsoft</a>)
43 <dd class=vcard><a class=fn href="http://dbaron.org/">L. David Baron</a>
44 (<a class=org href="http://www.mozilla.org/">Mozilla</a>)
46 <dt>Issues list:
47 <dd><a href="https://www.w3.org/Bugs/Public/buglist.cgi?query_format=advanced&product=CSS&component=Animations&resolution=---&cmdtype=doit">in Bugzilla</a>
49 <dt>Discussion:
50 <dd><a href="http://lists.w3.org/Archives/Public/www-style/">www-style@w3.org</a> with subject line “<kbd>[[SHORTNAME]] <var>… message topic …</var></kbd>”
52 <dt>Test suite:
53 <dd>none yet
54 </dl>
56 <!--copyright-->
58 <hr title="Separator for header">
59 </div>
61 <h2 class="no-num no-toc" id="abstract">
62 Abstract</h2>
64 <p>
65 This CSS module describes a way for authors to animate the values of CSS properties over time,
66 using keyframes.
67 The behavior of these keyframe animations can be controlled by specifying their duration,
68 number of repeats,
69 and repeating behavior.
72 <h2 class="no-num no-toc" id="status">
73 Status of this document</h2>
74 <!--status-->
77 <h2 class="no-num no-toc" id="contents">
78 Table of contents</h2>
79 <!--toc-->
82 <h2 id="introduction">
83 Introduction</h2>
85 <p><em>This section is not normative.</em>
87 <p>
88 CSS Transitions [[CSS3-TRANSITIONS]]
89 provide a way to interpolate CSS property values
90 when they change as a result of underlying property changes.
91 This provides an easy way to do simple animation,
92 but the start and end states of the animation are controlled by the existing property values,
93 and transitions provide little control to the author on how the animation progresses.
95 <p>
96 This proposal introduces <dfn>defined animations</dfn>,
97 in which the author can specify the changes in CSS properties over time as a set of keyframes.
98 Animations are similar to transitions
99 in that they change the presentational value of CSS properties over time.
100 The principal difference is that
101 while transitions trigger <em>implicitly</em> when property values change,
102 animations are <em>explicitly</em> executed when the animation properties are applied.
103 Because of this,
104 animations require explicit values for the properties being animated.
105 These values are specified using animation keyframes, described below.
107 <p>
108 Many aspects of the animation can be controlled,
109 including how many times the animation iterates,
110 whether or not it alternates between the begin and end values,
111 and whether or not the animation should be running or paused.
112 An animation can also delay its start time.
115 <h2 id="animations">
116 Animations</h2>
118 <p>
119 CSS Animations affect computed property values.
120 During the execution of an animation,
121 the computed value for a property is controlled by the animation.
122 This overrides the value specified in the normal styling system.
123 Animations override all normal rules, but are overriden by
124 !important rules.
126 <p>
127 If at one point in time there are multiple animations specifying behavior for the same property,
128 the animation whose name occurs last in the value of 'animation-name'
129 will override the other animations at that point.
132 <p>
133 An animation does not affect the computed value before the application of the animation,
134 before the animation delay has expired,
135 and after the end of the animation.
138 <div class="figure">
139 <img src="sandwich.png" alt="">
141 <p class="caption">
142 Computation of animated property values
143 </div>
145 <p>
146 The diagram above shows how property values are computed.
147 The intrinsic style is shown at the top of the diagram.
148 The computed value is derived from intrinsic style
149 at the times when an animation is not running
150 and also when an animation is delayed
151 (see below for specification of animation delay).
152 During an animation,
153 the computed style is derived from the animated value.
156 <p>
157 The start time of an animation is the latter of two moments:
158 the time at which the style is resolved that specifies the animation,
159 or the time the document's load event is fired.
160 Therefore, an animation specified in the document style sheet
161 will begin at the document load.
162 An animation specified on an element by modifying the style after the document has loaded
163 will start when the style is resolved.
164 That may be immediately in the case of a pseudo style rule such as hover,
165 or may be when the scripting engine returns control to the browser
166 (in the case of style applied by script).
169 <p>
170 An animation applies to an element
171 if the element has a value for 'animation-name' that references a valid keyframes rule.
172 Once an animation has started
173 it continues until it ends
174 or the 'animation-name' is removed.
175 The values used for the keyframes and animation properties are snapshotted at the time the animation starts.
176 Changing them during the execution of the animation has no effect.
177 Note also that changing the value of 'animation-name' does not necessarily restart an animation
178 (e.g., if a list of animations are applied and one is removed from the list,
179 only that animation will stop;
180 The other animations will continue).
181 In order to restart an animation,
182 it must be removed then reapplied.
185 <p>
186 The end of the animation is defined by the combination of the
187 'animation-duration',
188 'animation-iteration-count' and
189 'animation-fill-mode' properties.
192 <div class="example">
193 <pre>
194 div {
195 animation-name: diagonal-slide;
196 animation-duration: 5s;
197 animation-iteration-count: 10;
198 }
200 @keyframes diagonal-slide {
202 from {
203 left: 0;
204 top: 0;
205 }
207 to {
208 left: 100px;
209 top: 100px;
210 }
212 }</pre>
214 <p>
215 This will produce an animation
216 that moves an element from (0, 0) to (100px, 100px)
217 over five seconds
218 and repeats itself nine times
219 (for a total of ten iterations).
220 </div>
222 <p>
223 Setting the display property to 'none' will terminate any running animation
224 applied to the element and its descendants.
226 If an element has a display of 'none', updating display to a value other than 'none'
227 will start all animations applied to the element by the 'animation-name' property,
228 as well as all animations applied to descendants with display other than 'none'.
229 </p>
231 <h2 id="keyframes">
232 Keyframes</h2>
233 <p>
234 Keyframes are used to specify the values for the animating properties
235 at various points during the animation.
236 The keyframes specify the behavior of one cycle of the animation;
237 the animation may iterate one or more times.
239 <p>
240 Keyframes are specified using a specialized CSS at-rule.
241 A @keyframes rule consists of the keyword "@keyframes",
242 followed by an identifier giving a name for the animation
243 (which will be referenced using 'animation-name'),
244 followed by a set of style rules
245 (delimited by curly braces).
247 <p>
248 The <dfn>keyframe selector</dfn> for a keyframe style rule
249 consists of a comma-separated list of percentage values
250 or the keywords 'from' or 'to'.
251 The selector is used to specify the percentage along the duration of the animation that the keyframe represents.
252 The keyframe itself is specified by the block of property values declared on the selector.
253 The keyword 'from' is equivalent to the value ''0%''.
254 The keyword 'to' is equivalent to the value ''100%''.
255 <span class='note'>Note that the percentage unit specifier must be used on percentage values.
256 Therefore, ''0'' is an invalid keyframe selector.</span>
258 <p>
259 If a ''0%'' or ''from'' keyframe is not specified,
260 then the user agent constructs a ''0%'' keyframe
261 using the computed values of the properties being animated.
262 If a ''100%'' or ''to'' keyframe is not specified,
263 then the user agent constructs a ''100%'' keyframe
264 using the computed values of the properties being animated.
265 If a keyframe selector specifies
266 negative percentage values or
267 values higher than 100%,
268 then the keyframe will be ignored.
270 <p>
271 The <dfn>keyframe declaration block</dfn> for a keyframe rule
272 consists of properties and values.
273 Properties that are unable to be animated are ignored in these rules,
274 with the exception of 'animation-timing-function',
275 the behavior of which is described below. In addition, keyframe rule declarations qualified with !important are ignored.
277 <p class="issue">
278 Need to describe what happens if a property is not present in all keyframes.
280 <p>
281 The @keyframes rule that is used by an animation
282 will be the last one encountered in sorted rules order
283 that matches the name of the animation specified by the 'animation-name' property.
284 @keyframes rules do not cascade;
285 therefore, an animation will never derive keyframes from more than one @keyframes rule.
287 <p class='note'>
288 Note that since empty @keyframes rule are valid, they may hide the keyframes of
289 those preceding animation definitions with a matching name.
291 <p>
292 To determine the set of keyframes,
293 all of the values in the selectors are sorted in increasing order by time.
294 If there are any duplicates,
295 then the last keyframe specified inside the @keyframes rule
296 will be used to provide the keyframe information for that time.
297 There is no cascading within a @keyframes rule if multiple keyframes specify the same keyframe selector values.
299 <p>
300 If a property is not specified for a keyframe,
301 or is specified but invalid,
302 the animation of that property proceeds as if that keyframe did not exist.
303 Conceptually,
304 it is as if a set of keyframes is constructed for each property that is present in any of the keyframes,
305 and an animation is run independently for each property.
307 <div class="example">
308 <pre>
309 @keyframes wobble {
310 0% {
311 left: 100px;
312 }
314 40% {
315 left: 150px;
316 }
318 60% {
319 left: 75px;
320 }
322 100% {
323 left: 100px;
324 }
325 }</pre>
327 <p>
328 Four keyframes are specified for the animation named "wobble".
329 In the first keyframe,
330 shown at the beginning of the animation cycle,
331 the value of the 'left' property being animated is ''100px''.
332 By 40% of the animation duration,
333 'left' has animated to ''150px''.
334 At 60% of the animation duration,
335 'left' has animated back to ''75px''.
336 At the end of the animation cycle,
337 the value of 'left' has returned to ''100px''.
338 The diagram below shows the state of the animation if it were given a duration of ''10s''.
340 <div class="figure">
341 <img src="animation1.png" alt="">
343 <p class="caption">
344 Animations states specified by keyframes
345 </div>
346 </div>
348 <p>
349 The following is the grammar for the keyframes rule.
351 <pre>
352 keyframes_rule: KEYFRAMES_SYM S+ IDENT S* '{' S* keyframes_blocks '}' S*;
354 keyframes_blocks: [ keyframe_selector '{' S* declaration? [ ';' S* declaration? ]* '}' S* ]* ;
356 keyframe_selector: [ FROM_SYM | TO_SYM | PERCENTAGE ] S* [ ',' S* [ FROM_SYM | TO_SYM | PERCENTAGE ] S* ]*;
358 @{K}{E}{Y}{F}{R}{A}{M}{E}{S} {return KEYFRAMES_SYM;}
359 {F}{R}{O}{M} {return FROM_SYM;}
360 {T}{O} {return TO_SYM;}</pre>
363 <h3 id="timing-functions">
364 Timing functions for keyframes</h3>
366 <p>
367 A keyframe style rule may also declare the timing function that is to be used
368 as the animation moves to the next keyframe.
370 <div class="example">
371 <pre>
372 @keyframes bounce {
374 from {
375 top: 100px;
376 animation-timing-function: ease-out;
377 }
379 25% {
380 top: 50px;
381 animation-timing-function: ease-in;
382 }
384 50% {
385 top: 100px;
386 animation-timing-function: ease-out;
387 }
389 75% {
390 top: 75px;
391 animation-timing-function: ease-in;
392 }
394 to {
395 top: 100px;
396 }
398 }</pre>
400 <p>
401 Five keyframes are specified for the animation named "bounce".
402 Between the first and second keyframe
403 (i.e., between 0% and 25%)
404 an ''ease-out'' timing function is used.
405 Between the second and third keyframe
406 (i.e., between 25% and 50%)
407 an ''ease-in'' timing function is used.
408 And so on.
409 The effect will appear as an element that moves up the page ''50px'',
410 slowing down as it reaches its highest point
411 then speeding up as it falls back to ''100px''.
412 The second half of the animation behaves in a similar manner,
413 but only moves the element ''25px'' up the page.
414 </div>
416 <p>
417 A timing function specified on the "to" or 100% keyframe is ignored.
419 <p>
420 See the 'animation-timing-function' property for more information.
423 <h3 id="animation-name-property">
424 The 'animation-name' Property</h3>
426 <p>
427 The 'animation-name' property defines a list of animations that apply.
428 Each name is used to select the keyframe at-rule
429 that provides the property values for the animation.
430 If the name does not match any keyframe at-rule,
431 there are no properties to be animated
432 and the animation will not execute.
433 Furthermore,
434 if the animation name is ''none''
435 then there will be no animation.
436 This can be used to override any animations coming from the cascade.
437 If multiple animations are attempting to modify the same property,
438 then the animation closest to the end of the list of names wins.
440 <p id="list-matching">
441 Each animation listed by name
442 should have a corresponding value for the other animation properties listed below.
443 If the lists of values for the other animation properties do not have the same length,
444 the length of the 'animation-name' list
445 determines the number of items in each list examined when starting animations.
446 The lists are matched up from the first value:
447 excess values at the end are not used.
448 If one of the other properties doesn't have enough comma-separated values to match the number of values of 'animation-name',
449 the UA must calculate its used value by repeating the list of values until there are enough.
450 This truncation or repetition does not affect the computed value.
451 <span class="note">Note: This is analogous to the behavior of the 'background-*'properties,
452 with 'background-image' analogous to 'animation-name'.</span>
455 <table class=propdef>
456 <tr>
457 <th>Name:</th>
458 <td><dfn>animation-name</dfn>
459 <tr>
460 <th><a href="#values">Value</a>:
461 <td><span><single-animation-name></span> [ ',' <span><single-animation-name></span> ]*
462 <tr>
463 <th>Initial:
464 <td>''none''
465 <tr>
466 <th>Applies To:
467 <td>all elements
468 <tr>
469 <th>Inherited:
470 <td>no
471 <tr>
472 <th>Animatable:
473 <td>no
474 <tr>
475 <th>Percentages:
476 <td>N/A
477 <tr>
478 <th>Media:
479 <td>visual
480 <tr>
481 <th>Computed Value:
482 <td>As specified
483 <tr>
484 <th>Canonical Order:
485 <td><abbr title="follows order of property value definition">per grammar</abbr>
486 </table>
488 <div class="prod">
489 <dfn id="single-animation-name"><single-animation-name></dfn> = none | <IDENT>
490 </div>
492 <!--
493 <p>
494 It is possible for elements to have multiple animations running that change the same property or properties. In this case the animations combine in a manner defined by the property. For example, animations on 'opacity' will add together and animations on 'transform' will have their transformation matrices multiplied.
496 <div class="example">
497 <p style="display:none">
498 Example(s):
500 <pre>
501 @keyframes 'border-bloat' {
502 from {
503 border-width: 0;
504 }
505 to {
506 border-width: 10px;
507 }
508 }
510 @keyframes 'border-diet' {
511 from {
512 border-width: 4px;
513 }
514 to {
515 border-width: 2px;
516 }
517 }
519 div {
520 animation-name: 'border-bloat', 'border-diet';
521 animation-duration: 10s, 4s;
522 }
523 </pre>
524 <p>
525 The above example has two animations executing on the same property, 'border-width'. The animations are additive. That is, the
526 resulting value for the property will be the addition of the values from the
527 two animations.
529 <p>
530 At time '0s' the element's border will be 4px wide (0px from 'border-bloat' plus 4px from 'border-diet').
531 At time '4s' the element's border will be 6px wide (4px from 'border-bloat' plus 2px from 'border-diet').
532 At time '10s' the element's border will be 10px wide (10px from 'border-bloat' and no addition from
533 'border-diet' as it is no longer executing).
535 </div>
536 -->
539 <h3 id="animation-duration-property">
540 The 'animation-duration' Property</h3>
542 <p>
543 The 'animation-duration' property defines the length of time that an animation takes to complete one cycle.
546 <table class=propdef>
547 <tr>
548 <th>Name:</th>
549 <td><dfn>animation-duration</dfn>
550 <tr>
551 <th><a href="#values">Value</a>:
552 <td> <span><time></span> [, <span><time></span>]*
553 <tr>
554 <th>Initial:
555 <td>''0s''
556 <tr>
557 <th>Applies To:
558 <td>all elements
559 <tr>
560 <th>Inherited:
561 <td>no
562 <tr>
563 <th>Animatable:
564 <td>no
565 <tr>
566 <th>Percentages:
567 <td>N/A
568 <tr>
569 <th>Media:
570 <td>visual
571 <tr>
572 <th>Computed Value:
573 <td>as specified
574 <tr>
575 <th>Canonical Order:
576 <td><abbr title="follows order of property value definition">per grammar</abbr>
577 </table>
579 <p>
580 The initial value is ''0s'',
581 meaning that the animation takes no time.
582 When the duration is ''0s'' 'animation-fill-mode' still applies,
583 so an animation that fills backwards
584 will show the value of the 0% keyframe during any delay period,
585 and an animation that fills forwards will retain the value specified at the 100% keyframe,
586 even if the animation was instantaneous.
587 Also, animation events are still fired.
588 A negative 'animation-duration' value renders the declaration invalid.
591 <h3 id="animation-timing-function-property">
592 The 'animation-timing-function' Property</h3>
594 <p>
595 The 'animation-timing-function' property describes how the animation will progress over one cycle of its duration.
596 See the 'transition-timing-function' property [[!CSS3-TRANSITIONS]] for a complete description of timing function calculation.
598 <table class=propdef>
599 <tr>
600 <th>Name:</th>
601 <td><dfn>animation-timing-function</dfn>
602 <tr>
603 <th><a href="#values">Value</a>:
604 <td><span><single-timing-function></span> [ ',' <span><single-timing-function></span> ]*
605 <tr>
606 <th>Initial:
607 <td>''ease''
608 <tr>
609 <th>Applies To:
610 <td>all elements
611 <tr>
612 <th>Inherited:
613 <td>no
614 <tr>
615 <th>Animatable:
616 <td>no
617 <tr>
618 <th>Percentages:
619 <td>N/A
620 <tr>
621 <th>Media:
622 <td>visual
623 <tr>
624 <th>Computed Value:
625 <td>as specified
626 <tr>
627 <th>Canonical Order:
628 <td><abbr title="follows order of property value definition">per grammar</abbr>
629 </table>
631 <p>All the valid values of ''<single-timing-function>'' are defined by the 'transition-timing-function' property [[!CSS3-TRANSITIONS]].</p>
633 <p>
634 For a keyframed animation,
635 the 'animation-timing-function' applies between keyframes,
636 not over the entire animation.
637 For example,
638 in the case of an ''ease-in-out'' timing function,
639 an animation will ease in at the start of the keyframe
640 and ease out at the end of the keyframe.
641 An 'animation-timing-function' defined within a keyframe block applies to that keyframe,
642 otherwise the timing function specified for the animation is used.
645 <h3 id="animation-iteration-count-property">
646 The 'animation-iteration-count' Property</h3>
648 <p>
649 The 'animation-iteration-count' property specifies the number of times an animation cycle is played.
650 The initial value is ''1'',
651 meaning the animation will play from beginning to end once.
652 A value of ''infinite'' will cause the animation to repeat forever.
653 Non-integer numbers will cause the animation to end part-way through a cycle.
654 Negative values of 'animation-iteration-count' are invalid.
655 This property is often used in conjunction an 'animation-direction' value of ''alternate'',
656 which will cause the animation to play in reverse on alternate cycles.
658 <table class=propdef>
659 <tr>
660 <th>Name:</th>
661 <td><dfn>animation-iteration-count</dfn>
662 <tr>
663 <th><a href="#values">Value</a>:
664 <td><span><single-animation-iteration-count></span> [ ',' <span><single-animation-iteration-count></span> ]*
665 <tr>
666 <th>Initial:
667 <td>''1''
668 <tr>
669 <th>Applies To:
670 <td>all elements
671 <tr>
672 <th>Inherited:
673 <td>no
674 <tr>
675 <th>Animatable:
676 <td>no
677 <tr>
678 <th>Percentages:
679 <td>N/A
680 <tr>
681 <th>Media:
682 <td>visual
683 <tr>
684 <th>Computed Value:
685 <td>as specified
686 <tr>
687 <th>Canonical Order:
688 <td><abbr title="follows order of property value definition">per grammar</abbr>
689 </table>
691 <div class="prod">
692 <dfn id="single-animation-iteration-count"><single-animation-iteration-count></dfn> =
693 infinite | <number>
694 </div>
696 <h3 id="animation-direction-property">
697 The 'animation-direction' Property</h3>
699 <p>
700 The 'animation-direction' property defines whether or not the animation should play in reverse on some or all cycles.
701 When an animation is played in reverse the timing functions are also reversed.
702 For example, when played in reverse an ease-in animation would appear to be an ease-out animation.
704 <table class=propdef>
705 <tr>
706 <th>Name:</th>
707 <td><dfn>animation-direction</dfn>
708 <tr>
709 <th><a href="#values">Value</a>:
710 <td><span><single-animation-direction></span> [ ',' <span><single-animation-direction></span> ]*
711 <tr>
712 <th>Initial:
713 <td>''normal''
714 <tr>
715 <th>Applies To:
716 <td>all elements
717 <tr>
718 <th>Inherited:
719 <td>no
720 <tr>
721 <th>Animatable:
722 <td>no
723 <tr>
724 <th>Percentages:
725 <td>N/A
726 <tr>
727 <th>Media:
728 <td>visual
729 <tr>
730 <th>Computed Value:
731 <td>as specified
732 <tr>
733 <th>Canonical Order:
734 <td><abbr title="follows order of property value definition">per grammar</abbr>
735 </table>
737 <div class="prod">
738 <dfn id="single-animation-direction"><single-animation-direction></dfn> =
739 normal | reverse | alternate | alternate-reverse
740 </div>
742 <dl>
743 <dt><dfn>normal</dfn>
744 <dd>
745 All iterations of the animation are played as specified.
747 <dt><dfn>reverse</dfn>
748 <dd>
749 All iterations of the animation are played in the reverse direction from the way they were specified.
751 <dt><dfn>alternate</dfn>
752 <dd>
753 The animation cycle iterations that are odd counts are played in the normal direction,
754 and the animation cycle iterations that are even counts are played in a reverse direction.
756 <dt><dfn>alternate-reverse</dfn>
757 <dd>
758 The animation cycle iterations that are odd counts are played in the reverse direction,
759 and the animation cycle iterations that are even counts are played in a normal direction.
760 </dl>
762 <p class='note'>
763 Note that for the purpose of determining whether an iteration is even or odd,
764 iterations start counting from 1.
767 <h3 id="animation-play-state-property">
768 The 'animation-play-state' Property</h3>
770 <p>
771 The 'animation-play-state' property defines whether the animation is running or paused.
772 A running animation can be paused by setting this property to ''paused''.
773 To continue running a paused animation this property can be set to ''running''.
774 A paused animation will continue to display the current value of the animation in a static state,
775 as if the time of the animation is constant.
776 When a paused animation is resumed,
777 it restarts from the current value,
778 not necessarily from the beginning of the animation.
780 <table class=propdef>
781 <tr>
782 <th>Name:</th>
783 <td><dfn>animation-play-state</dfn>
784 <tr>
785 <th><a href="#values">Value</a>:
786 <td><span><single-animation-play-state></span> [ ',' <span><single-animation-play-state></span> ]*
787 <tr>
788 <th>Initial:
789 <td>''running''
790 <tr>
791 <th>Applies To:
792 <td>all elements
793 <tr>
794 <th>Inherited:
795 <td>no
796 <tr>
797 <th>Animatable:
798 <td>no
799 <tr>
800 <th>Percentages:
801 <td>N/A
802 <tr>
803 <th>Media:
804 <td>visual
805 <tr>
806 <th>Computed Value:
807 <td>as specified
808 <tr>
809 <th>Canonical Order:
810 <td><abbr title="follows order of property value definition">per grammar</abbr>
811 </table>
813 <div class="prod">
814 <dfn id="single-animation-play-state"><single-animation-play-state></dfn> =
815 running | paused
816 </div>
818 <h3 id="animation-delay-property">
819 The 'animation-delay' Property</h3>
821 <p>
822 The 'animation-delay' property defines when the animation will start.
823 It allows an animation to begin execution some time after it is applied.
824 An 'animation-delay' value of ''0s'' means the animation will execute as soon as it is applied.
825 Otherwise, the value specifies an offset from the moment the animation is applied,
826 and the animation will delay execution by that offset.
828 <p>
829 If the value for 'animation-delay' is a negative time offset
830 then the animation will execute the moment it is applied,
831 but will appear to have begun execution at the specified offset.
832 That is, the animation will appear to begin part-way through its play cycle.
833 In the case where an animation has implied starting values and a negative 'animation-delay',
834 the starting values are taken from the moment the animation is applied.
836 <table class=propdef>
837 <tr>
838 <th>Name:</th>
839 <td><dfn>animation-delay</dfn>
840 <tr>
841 <th><a href="#values">Value</a>:
842 <td> <span><time></span> [, <span><time></span>]*
843 <tr>
844 <th>Initial:
845 <td>''0s''
846 <tr>
847 <th>Applies To:
848 <td>all elements
849 <tr>
850 <th>Inherited:
851 <td>no
852 <tr>
853 <th>Animatable:
854 <td>no
855 <tr>
856 <th>Percentages:
857 <td>N/A
858 <tr>
859 <th>Media:
860 <td>visual
861 <tr>
862 <th>Computed Value:
863 <td>as specified
864 <tr>
865 <th>Canonical Order:
866 <td><abbr title="follows order of property value definition">per grammar</abbr>
867 </table>
870 <h3 id="animation-fill-mode-property">
871 The 'animation-fill-mode' Property</h3>
873 <p>
874 The 'animation-fill-mode' property defines what values are applied by the animation outside the time it is executing.
875 By default, an animation will not affect property values
876 between the time it is applied
877 (the 'animation-name' property is set on an element)
878 and the time it begins execution
879 (which is determined by the 'animation-delay' property).
880 Also, by default an animation does not affect property values after the animation ends
881 (determined by the 'animation-duration' property).
882 The 'animation-fill-mode' property can override this behavior.
884 <p>
885 If the value for 'animation-fill-mode' is ''backwards'',
886 then the animation will apply
887 the property values defined in the keyframe
888 that will start the first iteration of the animation,
889 during the period defined by 'animation-delay'.
890 These are either the values of the ''from'' keyframe
891 (when 'animation-direction' is ''normal'' or ''alternate'')
892 or those of the ''to'' keyframe
893 (when 'animation-direction' is ''reverse'' or ''alternate-reverse'').
895 <p>
896 If the value for 'animation-fill-mode' is ''forwards'',
897 then after the animation ends
898 (as determined by its 'animation-iteration-count'),
899 the animation will apply
900 the property values for the time the animation ended.
901 When 'animation-iteration-count' is an integer greater than zero,
902 the values applied will be
903 those for the end of the last completed iteration of the animation
904 (rather than the values for
905 the start of the iteration that would be next).
906 When 'animation-iteration-count' is zero,
907 the values applied will be those that would start the first iteration
908 (just as when 'animation-fill-mode' is ''backwards'').
910 <p>
911 If the value for 'animation-fill-mode' is ''both'',
912 then the animation will follow the rules for both 'forwards' and 'backwards'.
913 That is, it will extend the animation properties in both directions.
915 <table class=propdef>
916 <tr>
917 <th>Name:</th>
918 <td><dfn>animation-fill-mode</dfn>
919 <tr>
920 <th><a href="#values">Value</a>:
921 <td><span><single-animation-fill-mode></span> [ ',' <span><single-animation-fill-mode></span> ]*
922 <tr>
923 <th>Initial:
924 <td>''none''
925 <tr>
926 <th>Applies To:
927 <td>all elements
928 <tr>
929 <th>Inherited:
930 <td>no
931 <tr>
932 <th>Animatable:
933 <td>no
934 <tr>
935 <th>Percentages:
936 <td>N/A
937 <tr>
938 <th>Media:
939 <td>visual
940 <tr>
941 <th>Computed Value:
942 <td>as specified
943 <tr>
944 <th>Canonical Order:
945 <td><abbr title="follows order of property value definition">per grammar</abbr>
946 </table>
948 <div class="prod">
949 <dfn id="single-animation-fill-mode"><single-animation-fill-mode></dfn> =
950 none | forwards | backwards | both
951 </div>
953 <h3 id="animation-shorthand-property">
954 The 'animation' Shorthand Property
956 <p>
957 The 'animation' shorthand property is a comma-separated list of
958 animation definitions, each of which combines seven of the animation properties
959 into a single component value.
961 <table class=propdef>
962 <tr>
963 <th>Name:</th>
964 <td><dfn>animation</dfn>
965 <tr>
966 <th><a href="#values">Value</a>:
967 <td><span><single-animation></span> [ ',' <span><single-animation></span> ]*
968 <tr>
969 <th>Initial:
970 <td>see individual properties
971 <tr>
972 <th>Applies To:
973 <td>all elements
974 <tr>
975 <th>Inherited:
976 <td>see individual properties
977 <tr>
978 <th>Animatable:
979 <td>no
980 <tr>
981 <th>Percentages:
982 <td>N/A
983 <tr>
984 <th>Media:
985 <td>visual
986 <tr>
987 <th>Computed Value:
988 <td>see individual properties
989 <tr>
990 <th>Canonical Order:
991 <td><abbr title="follows order of property value definition">per grammar</abbr>
992 </table>
994 <div class="prod">
995 <dfn id="single-animation"><single-animation></dfn> =
996 <single-animation-name> ||
997 <span><time></span> ||
998 <single-animation-timing-function> ||
999 <span><time></span> ||
1000 <single-animation-iteration-count> ||
1001 <single-animation-direction> ||
1002 <single-animation-fill-mode>
1003 </div>
1005 <p>
1006 Note that order is important within each animation definition:
1007 the first value that can be parsed as a <var><time></var> is assigned to the
1008 animation-duration,
1009 and the second value that can be parsed as a <var><time></var> is assigned to
1010 animation-delay.
1011 </p>
1013 <p class="issue">
1014 An alternative proposal is to accept the font shorthand approach
1015 of using a "/" character between the values of the same type.
1016 e.g. 2s/4s would mean a duration of 2 seconds and a delay of 4 seconds.
1018 <p class="issue">
1019 Need to also explain how order is important in terms of animation-name
1020 versus keywords, and probably also adjust the canonical order to
1021 match.
1023 <h2 id="animation-events">
1024 Animation Events</h2>
1026 <p>
1027 Several animation related events are available through the <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html">DOM Event system</a>.
1028 The start and end of an animation,
1029 and the end of each iteration of an animation,
1030 all generate DOM events.
1031 An element can have multiple properties being animated simultaneously.
1032 This can occur either with a single 'animation-name' value
1033 with keyframes containing multiple properties,
1034 or with multiple 'animation-name' values.
1035 For the purposes of events,
1036 each 'animation-name' specifies a single animation.
1037 Therefore an event will be generated for each 'animation-name' value
1038 and not necessarily for each property being animated.
1040 <p>
1041 Any animation for which both a valid keyframe rule and a non-zero duration are
1042 defined will run and generate events; this includes animations with empty
1043 keyframe rules.
1045 <p>
1046 The time the animation has been running is sent with each event generated.
1047 This allows the event handler to determine the current iteration of a looping animation
1048 or the current position of an alternating animation.
1049 This time does not include any time the animation was in the ''paused'' play state.
1052 <h3 id='AnimationEvent-interface'>
1053 Interface <code>AnimationEvent</code>
1055 <p>
1056 The <dfn>AnimationEvent</dfn> interface provides specific contextual information associated with Animation events.
1059 <h4 id='AnimationEvent-IDL'>
1060 IDL Definition</h4>
1062 <pre class='idl'>
1063 [Constructor(DOMString <var title="">type</var>, optional <a href="#AnimationEventInit">AnimationEventInit</a> <var title="">eventInitDict</var>)]
1064 interface AnimationEvent : <a class="external" href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#event">Event</a> {
1065 readonly attribute DOMString <a href="#AnimationEvent-animationName" title="AnimationEvent-lengthComputable">animationName</a>;
1066 readonly attribute float <a href="#AnimationEvent-elapsedTime" title="dom-ProgressEvent-loaded">elapsedTime</a>;
1067 };
1069 dictionary AnimationEventInit : <a class="external" href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#eventinit">EventInit</a> {
1070 DOMString <span title="AnimationEventInit-animationName">animationName</span>;
1071 float <span title="AnimationEventInit-loaded">elapsedTime</span>;
1072 }
1074 </pre>
1077 <h4 id='AnimationEvent-attributes'>
1078 Attributes</h4>
1080 <dl>
1081 <dt><code><dfn id='AnimationEvent-animationName'>animationName</dfn></code> of type <code>DOMString</code>, readonly
1082 <dd>
1083 The value of the 'animation-name' property of the animation that fired the event.
1085 <dt><code><dfn id='AnimationEvent-elapsedTime'>elapsedTime</dfn></code> of type <code>float</code>, readonly
1086 <dd>
1087 The amount of time the animation has been running,
1088 in seconds,
1089 when this event fired,
1090 excluding any time the animation was paused.
1091 For an "animationstart" event,
1092 the elapsedTime is zero unless there was a negative value for 'animation-delay',
1093 in which case the event will be fired with an <code>elapsedTime</code> of (-1 * delay).
1094 </dl>
1096 <p>
1097 <code id="AnimationEvent-constructor">AnimationEvent(type, animEventDict)</code>
1098 is an <a class="external" href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-event-constructor">event constructor</a>.
1100 <h3 id='AnimationEvent-types'>
1101 Types of <code>AnimationEvent</code></h3>
1103 <p>
1104 The different types of Animation events that can occur are:
1106 <dl>
1107 <dt><dfn>animationstart</dfn>
1108 <dd>
1109 The <code>animationstart</code> event occurs at the start of the animation.
1110 If there is an 'animation-delay'
1111 then this event will fire once the delay period has expired.
1112 A negative delay will cause the event to fire with an <code>elapsedTime</code> equal to the absolute value of the delay.
1114 <ul>
1115 <li>Bubbles: Yes
1116 <li>Cancelable: No
1117 <li>Context Info: animationName
1118 </ul>
1120 <dt><dfn>animationend</dfn>
1121 <dd>
1122 The <code>animationend</code> event occurs when the animation finishes.
1124 <ul>
1125 <li>Bubbles: Yes
1126 <li>Cancelable: No
1127 <li>Context Info: animationName, elapsedTime
1128 </ul>
1130 <dt><dfn>animationiteration</dfn>
1131 <dd>
1132 The <code>animationiteration</code> event occurs at the end of each iteration of an animation,
1133 except when an <code>animationend</code> event would fire at the same time.
1134 This means that this event does not occur for animations with an iteration count of one or less.
1136 <ul>
1137 <li>Bubbles: Yes
1138 <li>Cancelable: No
1139 <li>Context Info: animationName, elapsedTime
1140 </ul>
1141 </dl>
1144 <h2 id="dom-interfaces">
1145 DOM Interfaces</h2>
1147 <p>
1148 CSS animation is exposed to the CSSOM through a pair of new interfaces describing the keyframes.
1151 <h3 id='CSSRule-interface'>
1152 Interface <code>CSSRule</code></h3>
1154 <p>
1155 The following 2 rule types are added to the <dfn>CSSRule</dfn> interface.
1156 They provide identification for the new keyframe and keyframes rules.
1159 <h4 id='CSSRule-IDL'>
1160 IDL Definition</h4>
1162 <pre class='idl'>
1163 interface CSSRule {
1164 ...
1165 const unsigned short KEYFRAMES_RULE = 7;
1166 const unsigned short KEYFRAME_RULE = 8;
1167 ...
1168 };</pre>
1171 <h3 id='CSSKeyframeRule-interface'>
1172 Interface <code>CSSKeyframeRule</code></3h>
1173 <p>
1174 The <dfn>CSSKeyframeRule</dfn> interface represents the style rule for a single key.
1177 <h4 id='CSSKeyframeRule-IDL'>
1178 IDL Definition</h4>
1180 <pre class='idl'>
1181 interface CSSKeyframeRule : CSSRule {
1182 attribute DOMString keyText;
1183 readonly attribute CSSStyleDeclaration style;
1184 };</pre>
1187 <h4 id='CSSKeyframeRule-attributes'>
1188 Attributes</h4>
1190 <dl>
1191 <dt><code><dfn id='CSSKeyframeRule-keyText'>keyText</dfn></code> of type <code>DOMString</code>
1192 <dd>
1193 This attribute represents the keyframe selector as a comma-separated
1194 list of percentage values. The ''from'' and ''to'' keywords map to
1195 ''0%'' and ''100%'', respectively.
1197 <dt><code><dfn id='CSSKeyframeRule-style'>style</dfn></code> of type <code>CSSStyleDeclaration</code>
1198 <dd>
1199 This attribute represents the style associated with this keyframe.
1200 </dl>
1203 <h3 id='CSSKeyframesRule-interface'>
1204 Interface <code>CSSKeyframesRule</code></h3>
1206 <p>
1207 The <dfn>CSSKeyframesRule</dfn> interface represents a complete set of keyframes for a single animation.
1210 <h4 id='CSSKeyframesRule-IDL'>
1211 IDL Definition</h4>
1213 <pre class='idl'>
1214 interface CSSKeyframesRule : CSSRule {
1215 attribute DOMString name;
1216 readonly attribute CSSRuleList cssRules;
1218 void appendRule(in DOMString rule);
1219 void deleteRule(in DOMString key);
1220 CSSKeyframeRule findRule(in DOMString key);
1221 };</pre>
1224 <h4 id='CSSKeyframesRule-attributes'>
1225 Attributes</h4>
1227 <dl>
1228 <dt><code><dfn id='CSSKeyframesRule-name'>name</dfn></code> of type <code>DOMString</code>
1229 <dd>
1230 This attribute is the name of the keyframes, used by the 'animation-name' property.<br>
1232 <dt><code><dfn id='CSSKeyframesRules-cssRules'>cssRules</dfn></code> of type <code>CSSRuleList</code>
1233 <dd>
1234 This attribute gives access to the keyframes in the list.
1237 <h4 id='CSSKeyframesRule-appendRule'>
1238 The <code>appendRule</code> method</h4>
1240 <p>
1241 The <dfn>appendRule</dfn> method appends the passed CSSKeyframeRule into the list at the passed key.
1243 <p>
1244 Parameters:
1246 <dl>
1247 <dt><code>rule</code> of type <code>DOMString</code>
1249 <dd>
1250 The rule to be appended,
1251 expressed in the same syntax as one entry in the ''@keyframes'' rule.
1252 </dl>
1254 <p>
1255 No Return Value
1257 <p>
1258 No Exceptions
1261 <h4 id='CSSKeyframesRules-deleteRule'>
1262 The <code>deleteRule</code> method</h4>
1264 <p>
1265 The <dfn>deleteRule</dfn> method deletes the CSSKeyframeRule with the passed key.
1266 If a rule with this key does not exist,
1267 the method does nothing.
1269 <p>
1270 Parameters:
1272 <dl>
1273 <dt><code>key</code> of type <code>DOMString</code>
1274 <dd>
1275 The key which describes the rule to be deleted.
1276 The key must resolve to a number between 0 and 1,
1277 or the rule is ignored.
1278 </dl>
1280 <p>
1281 No Return Value
1283 <p>
1284 No Exceptions
1287 <h4 id='CSSKeyframesRule-findRule'>
1288 The <code>findRule</code> method</h4>
1290 <p>
1291 The <code>findRule</code> method returns the rule with a key matching the passed key.
1292 If no such rule exists,
1293 a null value is returned.
1295 <p>
1296 Parameters:
1298 <dl>
1299 <dt><code>key</code> of type <code>DOMString</code>
1300 <dd>
1301 The key which described the rule to find.
1302 The key must resolve to a number between 0 and 1,
1303 or the rule is ignored.
1304 </dl>
1306 <p>
1307 Return Value:
1309 <dl>
1310 <dt><code>CSSKeyframeRule</code>
1311 <dd>
1312 The found rule.
1313 </dl>
1315 <p>
1316 No Exceptions
1319 <h2 id="acknowledgments">Acknowledgments</h2>
1321 <p>Thanks especially to the feedback from
1322 Tab Atkins,
1323 Carine Bournez,
1324 Estelle Weyl,
1325 and all the rest of the
1326 <a href="http://lists.w3.org/Archives/Public/www-style/">www-style</a> community.
1328 <h2>References</h2>
1330 <h3 class="no-num">Normative references</h3>
1331 <!--normative-->
1333 <h3 class="no-num">Other references</h3>
1334 <!--informative-->
1338 <h2 class="no-num">Property index</h2>
1339 <!-- properties -->
1343 <h2 class="no-num" id="index">Index</h2>
1344 <!--index-->
1346 </body>
1347 </html>
1348 <!-- Keep this comment at the end of the file
1349 Local variables:
1350 mode: sgml
1351 sgml-declaration:"~/SGML/HTML4.decl"
1352 sgml-default-doctype-name:"html"
1353 sgml-minimize-attributes:t
1354 sgml-nofill-elements:("pre" "style" "br")
1355 sgml-live-element-indicator:t
1356 sgml-omittag:nil
1357 sgml-shorttag:nil
1358 sgml-namecase-general:t
1359 sgml-general-insert-case:lower
1360 sgml-always-quote-attributes:t
1361 sgml-indent-step:nil
1362 sgml-indent-data:t
1363 sgml-parent-document:nil
1364 sgml-exposed-tags:nil
1365 sgml-local-catalogs:nil
1366 sgml-local-ecat-files:nil
1367 End:
1368 -->