This specification defines a model for synchronization and timing of changes to the presentation of a Web page. This specification also defines an application programming interface for interacting with this model and it is expected that further specifications will define declarative means for exposing these features.

## Introduction

Web Animations defines a model for supporting animation and synchronization on the Web platform. It is intended that other specifications will build on this model and expose its features through declarative means. In addition, this specification also defines a programming interface to the model that may be implemented by user agents that provide support for scripting.

### Use cases

The Web Animations model aims at two broad areas of application:

User interface effects

Animation can be used to give visual clues and feedback to make a user interface more readily comprehensible.

For example, a user action results in a table row being removed to represent an item being removed from a shopping cart. In such a case, fading the row to transparent and then shifting the subsequent rows up to fill the space over a few hundred milliseconds provides the user with clear feedback as to the results of their action as opposed to instantly removing the row from the DOM.

To support this scenario not only are the animated effects of fading and shifting required, but so is synchronization, both between the animations, and between animations and scripted actions (removing the table row from the DOM after the animations have completed).

Storytelling and visualisation

Another type of animation uses the animated effect to convey a story or represent some information. Unlike user interface effects which are largely a presentational adjunct to the content, these animations form an essential part of the content presented to the user.

For example, in an animated cartoon two cats fly through space to another planet leaving a rainbow trail behind them. After arriving at the planet a change of scene occurs and the user should decide whether or not the cats enter a magic mountain by selecting one of two preset destinations in the scene.

This scenario requires the following features:

• animated effects for moving characters along a path as well as warping a path (the rainbow trail),
• synchronization that allows some actions to happen simultaneously (the two cats moving) and others in sequence (the change of scene),
• play control to allow rewinding the cartoon, or changing its playback rate to accommodate particular learning or accessibility needs,
• the ability to trigger animations in response to user input

Similar use cases in this category include visualising physical phenomena such as spring motion for educational purposes, or visualising data such as the prevalence of a disease over a geographical space over a year whereby animation is used to present the time-based component of the data.

### Relationship to other specifications

CSS Transitions [[CSS3-TRANSITIONS]], CSS Animations [[CSS3-ANIMATIONS]], and SVG [[SVG11]] all provide mechanisms that generate animated content on a Web page. Although the three specifications provide many similar features, they are described in different terms. This specification proposes an abstract animation model that encompasses the common features of all three specifications. This model is backwards-compatible with the current behavior of these specifications such that they can be defined in terms of this model without any observable change.

The animation features in SVG 1.1 are defined in terms of SMIL Animation [[SMIL-ANIMATION]]. It is intended that by defining SVG's animation features in terms of the Web Animations model, the dependency between SVG and SMIL Animation can be removed.

The programming interface component of this specification makes some additions to interfaces defined in HTML5 [[HTML5]].

### Overview of this specification

This specification begins by defining an abstract model for animation. This is followed by a programming interface defined in terms of the abstract model. The programming interface is defined in terms of the abstract model and is only relevant to user agents that provide scripting support.

## Web Animations model overview

At a glance, the Web Animations model consists of two largely independent pieces, a timing model and an animation model. The role of these pieces is as follows:

Timing model
Takes a moment in time and converts it to a proportional distance within a single iteration of an animation called the time fraction. An iteration index is also generated for animations that vary as they repeat.
Animation model
Takes the time fractions and iteration indices produced by the timing model and converts them into a series of values to apply to the target properties and attributes.

Graphically, this flow can be represented as follows:

Overview of the operation of the Web Animations model.
The current time is input to the timing model which produces a time fraction and an iteration index.
These parameters are used as input to the animation model which produces the values to apply.

For example, consider an animation that:

• starts after 3 seconds,
• runs twice,
• takes 2 seconds every time, and
• changes the width of a rectangle from 50 pixels to 100 pixels.

The first three points apply to the timing model. At a time of 6 seconds, it will calculate that the animation should be half-way through its second iteration and produces the result 0.5. The animation model then uses that information to calculate a width for the rectangle of 75.

This specification begins with the timing model and then proceeds to the animation model.

## Timing model

This section describes and defines the behavior of the Web Animations timing model.

## The timing model at a glance

Two features characterise the Web Animations timing model: it is stateless and it is hierarchical.

### Stateless

The Web Animations timing model operates by taking an input time and producing an output time fraction. Since the output is based solely on the input time and is independent of previous inputs, the model may be described as stateless. This gives the model the following properties:

Frame-rate independent
Since the output is independent of previous inputs, the rate at which the model is sampled will not affect its progress. Provided the input times are proportional to the progress of real-world time, animations will progress at an identical rate regardless of the capabilities of the device running them.
Direction-agnostic
Since the sequence of inputs is insignificant, the model is directionless. This means that the model can be sampled in reverse or even in a backwards and forwards pattern without requiring any specialized handling.
Constant-time seeking
Since each input is independent of the previous input, the processing required to perform a seek operation, even far into the future, is at least potentially constant.

There are a few exceptions to the stateless behavior of the timing model.

Firstly, a number of methods defined in the programming interface to the model provide play control such as pausing an item. These methods are defined in terms of the time at which they are called and are therefore stative. These methods are provided primarily for convenience and are not part of the core timing model but are layered on top.

Likewise, player events are fired when the first sample occurs at the limit of the source content. This too is stative behavior but is part of the play control layered on top of the timing model.

Similarly, the limiting behavior of players means that dynamic changes to the end time of the media (source content) of a player may produce a different result depending on when the change occurs. This behavior is somewhat unfortunate but has been deemed intuitive and consistent with HTML. As a result, the model can only truly be described as stateless in the absence of dynamic changes to its timing properties.

Finally, each time the model is sampled, it can be considered to establish a temporary state. While this temporary state affects the values returned from the programming interface, it has no influence on the subsequent samples and hence does not conflict with the stateless qualities described above.

### Hierarchical

The other characteristic feature of the Web Animations timing model is that time is inherited. Time begins with a monotonically increasing time source and cascades down a number of steps to each animation. At each step, time may be shifted backwards and forwards, scaled, reversed, paused, and repeated.

A hierarchy of timing nodes. Each node in the tree derives its time from its parent node. At the root of the tree is the global clock.

A consequence of this hierarchical arrangement is that complex animation arrangements can be reversed, scheduled, accelerated and so on as a whole unit since the manipulations applied to the parent cascade down to its descendants. Furthermore, since time has a common source, it is easy to synchronize animations.

## Timing model concepts

In Web Animations, timing is based on a hierarchy of time relationships between timing nodes. Parent nodes provide timing information to their child nodes in the form of time values. A time value is a real number which nominally represents a number of milliseconds from some moment. The connection between time values and wall-clock milliseconds may be obscured by any number of transformations applied to the value as it passes through the time hierarchy.

In the future we may have timelines that are based on UI gestures in which case the connection between time values and milliseconds will be weakened even further.

Periodically, the user agent will trigger an update to the timing model in a process called sampling. On each sample the time values of each timing node are updated.

A more precise definition of when the model is updated when scripting is involved is provided in .

## The global clock

At the root of the Web Animations timing hierarchy is the global clock.

The global clock is a source of monotonically increasing time values unaffected by adjustments to the system clock. The time values produced by the global clock represent wall-clock milliseconds from an unspecified historical moment. Because the zero time of the global clock is not specified, the absolute values of the time values produced by the global clock are not significant, only their rate of change.

Note that the global clock is not exposed in the programming interface and nor is it expected to be exposed by markup. As a result the moment from which global clock time values are measured, that is, the zero time of the clock, is implementation-dependent. One user agent may measure the number of milliseconds since the the user agent was loaded whilst another may use the time when the device was started. Both approaches are acceptable and produce no observable difference in the output of the model.

## Timelines

A timeline provides a source of time values for the purpose of synchronization.

Typically, a timeline is tied to the global clock such that its absolute time is calculated as a fixed offset from the time of the global clock. This offset is established by designating some moment as the timeline's zero time and recording the time value of the global clock at that moment. At subsequent moments, the time value of the timeline is calculated as the difference between the current time value of the global clock and the value recorded at the zero time.

Note that we anticipate that other types of timelines may be introduced in the future that are not tied to the global clock. For example, a timeline whose time values are related to the progress of a UI gesture.

Since a timeline may be defined relative to a moment that has yet to occur, it may not always be able to return a meaningful time value. A timeline is considered to be not started when it is in such a state that it cannot produce a time value.

Should this be renamed to something like “inactive” so we can accommodate possible future timelines that may, after starting, become unable to return a meaningful time value?

### The document timeline

Each document has a timeline called the document timeline. The time values of the document timeline are calculated as a fixed offset from the global clock such that the zero time corresponds to the navigationStart moment [[!NAVIGATION-TIMING]]. Prior to this moment, the document timeline is not started.

Since the document timeline is tied to the global clock by a fixed offset, time values reported by the document timeline increase monotonically. Furthermore, since no scaling is applied, these time values are proportional to wall-clock milliseconds.

Since the time values of the document timeline are relative to the navigationStart time, document.timeline.currentTime will roughly correspond to Performance.now() [[HR-TIME]] with the exception that document.timeline.currentTime does not change within a script execution block as defined in .

## Players

The children of a timeline are called players. A player takes a timed item which is a static description of some timed behavior and binds it to a timeline so that it runs. A player also allows run-time control of the connection between the timed item and its timeline by providing pausing, seeking, and speed control. The relationship between a player and a timed item is analogous to that of a DVD player and a DVD.

A player connects a single timed item, called its source content, to a timeline and provides playback control.

A player's player start time is the time value of its timeline when its source content is initially scheduled to begin playback.

When a player is created, it is assigned a globally unique sequence number called the player sequence number. This number is used to resolve the sort order of players that have the same start time for a variety of situations such as combining animations, queuing events, and returning the list of current players.

### The current time of a player

Players provide a time value to their source content called the player's current time.

The calculation of the current time is as follows:

current time = (timeline time - adjusted start time) × playback rate

unless the hold time is not null, in which case the current time is equal to the hold time.

Where:

If the timeline with which the player is associated is not started then the current time is null.

The procedure for performing manual updates to the current time is defined in .

It is often useful to manipulate the current time of a player even when its associated timeline is not started, for example, to pre-seek a player. For this purpose, we have the following additional definitions:

effective timeline time
The current time value of the timeline associated with a player unless the timeline is not started, in which case the effective timeline time is zero.
effective current time
The result of evaluating the current time as above but substituting the effective timeline time for the timeline time.

### Seeking, pausing and limiting

Seeking, pausing and limiting a player are closely related and are described here together.

#### Introduction to seeking

Changing the current playback position of a player, that is, it's current time, can be used to rewind its source content to its start point, fast-forward to a point in the future, or to provide ad-hoc synchronization between timed items.

Changing the current time of a player has the side effect of updating its adjusted start time as illustrated below.

At time t, a seek is performed on the player changing its current time from 1.5s to 2s.
As a result, the adjusted start time is set to 0.5s.

Although the adjusted start time changes, the original player start time is preserved since it is used for determining the priority of competing animations as described in . This prioritorization should not change as a result of seeking.

It is possible to seek a player even if its timeline is not started. Once the timeline begins, the player will begin playback from the seeked time.

#### Introduction to pausing

Pausing can be used to temporarily suspend a player. Like seeking, pausing controls the current time of a player by updating its adjusted start time. The result is illustrated below.

The effect of pausing a player.
Whether pausing before or after a player's start time the duration of the interval during which the player was paused is added to the player's adjusted start time.

#### Limiting the current time

Players in the real world such as DVD players or cassette players typically continue playing until they reach the end of their media at which point they stop. If such players are able to play in reverse, they typically stop playing when they reach the beginning of their media. In order to emulate this behavior and to provide consistency with HTML's media elements [[HTML5]], the current time of Web Animations' players do not play forwards beyond the end time of their source content or play backwards past time zero. This behavior is called limiting.

Graphically, the effect of limiting is shown below.

The effect of limiting on a player with a start time of 1s, a source content of length 3s, and a positive player playback rate. After the current time of the player reaches the end of the source content, it is capped at 3s.

It is possible, however, to seek the current time of a player to a time past the end of the source content. When doing so, the current time will not progress but the player will act as if it had been paused at the seeked time.

This allows, for example, seeking the current time of a player with no source content to 5s. If source content with an end time later than 5s is later associated with the player, playback will begin from the 5s mark.

Similar behavior to the above scenarios may arise when the length of a player's source content changes.

When the player playback rate is negative, the current time does not progress past time zero although it may be seeked to a negative time.

Limiting the current time acts like a sort of automatic pausing and is accomplished using the same machinery as pausing.

#### Seeking, pausing and limiting properties

Players track three properties related to seeking, pausing and limiting.

The player start time after incorporating changes introduced by seeking, pausing, and limiting as defined in .
paused state
A boolean value that is true if the player is currently paused. The paused state is initially false.
hold time
The effective current time to maintain while the player is paused or effectively paused because it has reached the end of its source content and is limited. When neither of these conditions apply, the hold time is null. The hold time is initially null.

In addition to these properties, implementations are required to keep track of the last calculated value of the current time in order to produce correct limiting behavior (see ).

#### Calculating the adjusted start time

The adjusted start time value is both a stored and a calculated value. When a player is paused, the value is calculated from the hold time. When a player is not paused, the stored value is used. The stored value is initially equal to the player start time, and may be updated whenever the player is unpaused, seeked, becomes no longer limited, or when the player start time is updated.

The value of the adjusted start time at a given moment is based on the paused state as follows:

If the paused state is true,
Return the result of evaluating timeline time - hold time / player playback rate.
Otherwise,
Return the stored value for the adjusted start time.

#### Automatically updating the hold time

What should the behavior be here when the unlimited current time is null?

When the paused state is false, the hold time is updated on each sample according to the following procedure:

1. Let the unlimited current time be the result of evaluating the current time using a hold time of null.
2. Let the source content end be the end time of the player's source content. If the player has no source content, let the source content end be zero.
3. The hold time is updated using the first matching condition from below:
If the player playback rate < 0 and the unlimited current time ≤ 0,
Let the hold time be zero.
If the player playback rate > 0 and the unlimited current timesource content end,
Let the hold time be the maximum value of the last calculated value of current time and source content end. If there is no previously calculated value of current time or it is null, let the hold time be source content end.
Otherwise,
1. If the hold time is not null, set the stored value of the adjusted start time to the result of evaluating timeline time - unlimited current time / player playback rate.
2. Let the hold time be null.

Are there other times we need to run this procedure—other than on each sample?

#### Updating the paused state

The procedure for updating the paused state is as follows:

1. Let new value be the new paused state to set.
2. If new value equals the current paused state, abort this procedure.
3. The next step depends on the current paused state as follows,
If paused state is true and the player is not limited,
1. Set the stored value of adjusted start time to the current calculated value of adjusted start time as defined in .
2. Set the hold time to null.
Otherwise if the paused state is false,
Record the current value of the effective current time as hold time.
Otherwise,
Do nothing.
4. Update paused state to new value.

The above should probably use the effective current time when determining of the player is limited or not. But perhaps we should always use the effective current time in the definition of limited.

All the procedures in this section need to be audited to check they do the correct thing when the timeline is not started.

#### Performing a seek

Seeking is the process of updating a player's current time to a desired value. It is achieved using the following procedure:

1. Let seek time be the desired time value for the player's current time.
2. If any of the following conditions are true:
then set hold time to seek time.

Otherwise, if none of the above conditions are true,

1. Reset the hold time to null.
2. Set the adjusted start time to the result of evaluating timeline time - seek time / player playback rate.
3. Set the player's finished flag to false.

#### Updating the player start time

The start time of a player is updated to a new time, new start time, using the following procedure:

1. Let player start time be new start time.
2. Update the adjusted start time using the first matching condition from the following:
If the paused state is true,
Let the hold time be the result of evaluating timeline time - new start time × player playback rate.
Otherwise,
Let the adjusted start time be new start time.

#### Limited players

A player is said to be limited when either of the following conditions are true:

1. player playback rate > 0 and current time ≥ the player's source content end (as defined in ), or
2. player playback rate < 0 and current time ≤ zero.

### Speed control

The rate of play of a player can be controlled by setting its playback rate. For example, setting a playback rate of 2 will cause the player's current time to increase at twice the rate of its timeline. Similarly, a playback rate of -1 will cause the player's current time to decrease at the same rate as the time values from its timeline increase.

Note that timed items also have a playback rate associated with them that behaves differently to that defined here.

Players have a playback rate that provides a scaling factor from the rate of change of the associated timeline's time values to the player's current time. The playback rate is initially 1.

Setting a player's playback rate to zero effectively pauses the player but without affecting the player's paused state.

#### Updating the playback rate

Changes to the playback rate trigger a compensatory seek so that that the player's current time is unaffected by the change to the playback rate.

The procedure is as follows:

1. Let previous time be the value of the effective current time before updating the playback rate.
2. Update the playback rate to the new value.
3. Seek to previous time using the procedure defined in .
4. If the new value for the playback rate differs in sign to the previous non-zero playback rate, set the finished flag to false.

## Player events

As players play they report changes to their status through player events.

Player events are a property of the Web Animations timing model. As a result they are dispatched even when the source content of the player is absent or has no observable result.

### Types of player events

finish

Queued whenever a sample occurs that causes a player's finished flag to be newly true.

• Bubbles: no
• Cancelable: no
• Context Info: currentTime, documentTime

To assist dispatching finish events, players maintain a finished flag that is initially false when the player is created.

During each sample, the finished flag is updated such that it is set to true if the player is limited and false otherwise.

### Event parameters

Player events have an associated event current time and event timeline time.

The event current time is the current time of the player that generated the event at the moment the event is queued. This will be null if the player was not associated with a timeline at the time the event was generated.

The event timeline time is the time value of the timeline with which the player that generated the event is associated at the moment the event is queued. This will be null if the player was not associated with a timeline at the time the event was generated.

### Propagation path

The propagation path for a player event generated by player, is simply player itself.

### Sequence of events

The sequence in which player events are queued is in ascending order by event timeline time. If two player events have the same event document time, the player events are queued in ascending order by player sequence number of the players that generated the events.

### Event dispatch

Events are queued whenever sampling regularly occurs (that is, not when the timing model is evaluated due to seeking or structural changes to the hierarchy of timed items).

As a result, seeking a player to the limit of its source content and back to a point within its source content within the same script execution block will not trigger a finish event.

## Timed items

A timed item is an abstract term referring to a node in the timing hierarchy.

### Relationship between timed items and players

The source content of a player, if set, is a type of timed item. The source content of a player is said to be directly associated with that player.

Timed items can be combined together into a hierarchy using animation groups (see ). Only the root timed item of such a hierarchy can be directly associated with a player. If a timed item that has a parent animation group is designated as the source content of a player, the timed item is removed from its parent animation group before being associated with the player.

A timed item is associated with a player if it is directly associated with a player or if it has an ancestor animation group that is directly associated with a player. At a given moment, a timed item can be associated with at most one player.

A timed item, item, is associated with a timeline, timeline, if item is associated with a player which, in turn, is associated with timeline.

### Types of timed items

This specification defines two types of timed item:

All types of timed item define a number of common properties which are described in the following sections.

### The active interval

The period that a timed item is scheduled to run is called its active interval. Each timed item has only one such interval.

The lower bound of the active interval is determined by the start time of the timed item but may be shifted by a start delay on the timed item.

The upper bound of the interval is determined by the active duration.

The relationship between the start time, start delay, and active duration is illustrated below.

Examples of the effect of the start delay on the endpoints of the active interval.
(a) A timed item with no delay; the start time and beginning of the active interval are coincident.
(b) A timed item with a positive delay; the beginning of the active interval is deferred by the delay.
(c) A timed item with a negative delay; the beginning of the active interval is brought forward by the delay.

An end delay may also be specified but is primarily only of use when sequencing animations such as by using a sequence animation group.

Timed items define an active interval which is the period of time during which the item is scheduled to produce its effect with the exception of fill modes which apply outside the active interval.

The lower bound of the active interval is defined by the combination of the timed item's start time and start delay

A timed item's start time is the moment at which the parent animation group, if any, has scheduled the timed item to begin. It is expressed in inherited time. In most cases, including the case when the timed item has no parent animation group, the start time is zero. The singular exception is sequence animation groups which set the start times of their children as described in .

In addition to the start time, a timed item also has a start delay which is an offset from the start time. Unlike the start time which is determined by the parent animation group, the start delay is a property of the timed item itself.

The lower bound of the active interval of a timed item, expressed in inherited time space, is the sum of the start time and the start delay.

These definitions are incorporated in the calculation of the local time (see ) and active time.

The length of the active interval is called the active duration, the calculation of which is defined in .

Similar to the start delay, a timed item also has an end delay which may be used to delay the start time of the next sibling in a sequence animation group.

### Local time and inherited time

In Web Animations all times are relative to some point of reference. These different points of reference produce different time spaces.

This can be compared to coordinate spaces as used in computer graphics. The zero time of a time space is analogous to the origin of a coordinate space.

Just as with coordinate spaces, time spaces can also be nested. Animation groups typically perform some transformations on the time values they receive from their parent or player before passing on the transformed time values to their children. Child timed items then operate within that transformed time space.

Children take the transformed time values from their parent—called the inherited time— and add their start time to establish their own local time space as illustrated below.

Inherited time and local time.
At time t, the inherited time is 2.5.
For timed item (a) which has a start time of 1, the local time is 1.5.
For timed item (b) which has a start time of 1 and a start delay of 1, the local time is also 1.5 since local time is based on a timed item's start time only, and not on its start delay.

For a timed item, the inherited time at a given moment is based on the first matching condition from the following:

If the timed item has a parent animation group,
the inherited time is the parent animation group's current transformed time.
If the timed item is directly associated with a player,
the inherited time is the current time of the player.
Otherwise,
the inherited time is null.

The local time of a timed item is the timed item's inherited time minus its start time. If the inherited time is null then the local time is also null.

### Timed item phases and states

At a given moment, a timed item may be in one of three possible phases. If a timed item has a null local time it will not be in any phase.

The different phases are illustrated below.

An example of the different phases and states used to describe a timed item.

The phases are as follows:

before phase
The timed item's local time falls before the item's active interval.
active phase
The timed item's local time falls inside the item's active interval.
after phase
The timed item's local time falls after the item's active interval.

In addition to these phases, a timed item may also be described as being in one of several overlapping states. These states are only established for the duration of a single sample and are primarily a convenience for describing stative parts of the model.

These states and their useage within the model are summarised as follows:

in play

Corresponds to a timed item whose active time is changing on each sample. This occurs when the timed item and all its ancestors are in the active phase. Animations only “move” when they are in play.

It is possible for a timed item to be in the active phase but not in play. For example, if a timed item has a parent animation group that causes the timed item's active interval to be clipped and both parent and child apply the same fill mode, the child timed item may be effectively be snapshotted within the active phase despite no longer being in play.

current

Corresponds to a timed item that is either in play or may become in play in the future. This will be the case if the timed item is in play or in its before phase, or it has an ancestor for which this is true thereby opening up the possibility that this timed item might play again (e.g. due to repeating).

This state is used in the programming interface to identify all animations and players that are likely to be of interest.

Furthermore, the current state provides an important definition for managing the amount of memory required by implementations. Assuming a monotonically increasing timeline an implementation can safely discard all timed items that are not current and not referenced elsewhere provided they take care to preserve any fill values. This is because such timed items will no longer have any dynamic effect.

in effect
Corresponds to a timed item that has a resolved active time. This occurs when either the timed item is in its active phase or outside the active interval but at a time where the item's fill mode (see ) causes its active time to be resolved. Only in effect animations apply a result to their target.

The normative definition of each of these states follows.

A timed item is in the before phase if the timed item's local time is not null and is less than the item's start delay.

A timed item is in the active phase if all of the following conditions are met:

1. the timed item's local time is not null, and
2. the timed item's local time is greater than or equal to its start delay, and
3. the timed item's local time is less than the sum of its start delay and active duration.

A timed item is in the after phase if the timed item's local time is not null and is greater than or equal to the sum of its start delay and active duration.

A timed item is in play if all of the following conditions are met:

1. the timed item is in the active phase, and
2. the timed item has a parent animation group that is in play or else is directly associated with a player that is not limited.

A timed item is current if it any of the following conditions is true:

A timed item is in effect if its active time as calculated according to the procedure in is not null.

## Fill behavior

The effect of a timed item when it is not in play is determined by its fill mode.

The possible fill modes are:

• none,
• forwards,
• backwards, and
• both.

The normative definition of these modes is incorporated in the calculation of the active time in .

### Fill modes

The effect of each fill mode is as follows:

none
The timed item has no effect when it is not in play.
forwards
When the timed item is in the after phase, or when the timed item is in the active phase but an ancestor is in its after phase, the timed item will produce the same transformed time value as the last moment it is scheduled to be in play. For all other times that the timed item is not in play, it will have no effect.
backwards
When the timed item is in the before phase, or when the timed item is in the active phase but an ancestor is in its before phase, the timed item will produce the same transformed time value as the earliest moment that it is scheduled to be in play. For all other times that the timed item is not in play, it will have no effect.
both
When the timed item or an ancestor is in its before phase, backwards fill behavior is used. When the timed item or an ancestor is in its after phase, forwards fill behavior is used.

Some examples of the these fill modes are illustrated below.

Examples of various fill modes and the states produced.
(a) fill mode ‘none’. The timed item has no effect outside its active interval.
(b) fill mode ‘forwards’. After the active interval has finished, the timed value continues to maintain a fill value.
(c) fill mode ‘backwards’. The timed item produces a fill value until the start of the active interval.
(d) fill mode ‘both’. Both before and after the active interval the timed item produces a fill value.

Note that setting a fill mode has no bearing on the endpoints of the active interval. However, the fill mode does have an effect on various other properties of the timing model since the active time of a timed item is only defined (that is, not null) inside the active interval or when a fill is applied.

Currently timing functions that generate results outside the range [0, 1] will behave unexpectedly when applied to animation groups, as children will increase iterations or enter into fill mode rather than continuing to extrapolate along their defined behavior (which is what they would do if the timing function applied to them directly).

To fix this it is possible we will wish to introduce 'overflow' fill modes that respond to time values larger than or smaller than the active time range by extrapolating rather than filling.

## Repeating

### Iteration intervals

It is possible to specify that a timed item should repeat a fixed number of times or indefinitely. This repetition occurs within the active interval. The span of time during which a single repetition takes place is called an iteration interval.

Unlike the active interval, a timed item can have multiple iteration intervals although typically only the interval corresponding to the current iteration is of interest.

The length of a single iteration is called the iteration duration. The initial iteration duration of a timed item is simply its intrinsic iteration duration.

The intrinsic iteration duration of a timed item is zero, however some specific types of timed item such as animation groups override this behavior and provide an alternative intrinsic duration (see and ).

The iteration duration of a timed item may be set by the author to represent a value other than the intrinsic iteration duration.

Comparing the iteration duration and the active duration we have:

Iteration duration
The time taken for a single iteration of the timed item to complete.
Active duration
The time taken for the entire timed item to complete, including repetitions. This may be longer or shorter than the iteration duration.

The relationship between the iteration duration and active duration is illustrated below.

A comparison of the iteration duration and active duration of a timed item with an iteration count of 2.5. Note that the iteration duration for the final iteration does not change, it is simply cut-off by the active duration.

### Controlling iteration

The number of times a timed item repeats is called its iteration count. The iteration count is a real number greater than or equal to zero. The iteration count may also be positive infinity to represent that the timed item repeats indefinitely.

In addition to the iteration count, timed items also have an iteration start property which specifies an offset into the series of iterations at which the timed item should begin. The iteration start is a finite real number greater than or equal to zero.

The behavior of these parameters is defined in the calculations in .

The effect of the iteration count and iteration start parameters is illustrated below.

The effect of the iteration count and iteration start parameters.
In the first case the iteration count is 2.5 resulting in the third iteration being cut-off half way through its iteration interval.
The second case is the same but with an iteration start of 0.5. This causes the timed item to begin half way through the first iteration.

Unlike the iteration count parameter, the iteration start parameter does not effect the length of the active duration.

Note that values of iteration start greater than or equal to one are generally not useful unless used in combination with an animation effect that has an accumulation operation property of sum.

### Iteration time space

We have already encountered different time spaces in describing local time and inherited time (see ). Repetition introduces yet another time space: the iteration time space.

Iteration time space is a time space whose zero time is the beginning of a timed item's current iteration.

Within the Web Animations model we also refer to active time which is a time relative to the beginning of the active interval. This time space, however, is internal to the model and not exposed in the programming interface or in markup.

These time spaces are illustrated below.

A comparison of local time, active time, and iteration time for an animation with a iteration duration of 1s and an iteration count of 2.5.

Note that while the time spaces themselves are not bounded, Web Animations defines active time and iteration time such that they are clamped to a set range as shown in the diagram. For example, whilst a time of -1 second is a valid time in active time space, the procedure for calculating the active time defined in will never return a negative value.

In addition to these time spaces we can also refer to the document time space which is time space of the time values of the document timeline of the active document.

### Interval timing

When a timed item repeats we must define the behavior at the iteration boundaries. For this and indeed for all interval-timing, Web Animations uses an endpoint-exclusive timing model. This means that whilst the begin time of an interval is included in the interval, the end time time is not. In interval notation this can written [begin, end). This model provides sensible behavior when intervals are repeated and sequenced since there is no overlap between the intervals.

In the examples below, for the repeated item, at local time 1s, the iteration time is 0. For the sequenced items, at inherited time 1s, only item B will be in play; there is no overlap.

Illustration of end-point exclusive timing. For both repeated and sequenced timed items there is no overlap at the boundaries between intervals.

An exception to this behavior is that when performing a fill, if the fill begins at an interval endpoint, the endpoint is used. This behavior falls out of the algorithm given in and is illustrated below.

After one iteration, the iteration time is 0, but after two iterations (and thereonwards), the iteration time is equal to the iteration duration due to the special behavior defined when a timed item fills.

## Timed item speed control

Like players, timed items also have a playback rate parameter. The playback rate of a timed item is a finite real number that acts as a multiplier when calculating the timed item's transformed time from its local time.

The effect of setting the playback rate of a timed item differs from the setting the playback rate on a player. Its behavior is defined in the timing calculations given in .

In summary, the behavior of the playback rate of a timed item is as follows:

## Core timed item calculations

### Overview

At the core of the Web Animations timing model is the process that takes an inherited time value and converts it to an iteration time.

Following this further transformations are applied before resulting at a final transformed time.

The first step in this process is to calculate the bounds of the active interval which is determined by the active duration.

This process is illustrated below.

Calculation of the active duration is based on multiplying the iteration duration by the iteration count and then dividing by the playback rate.

The process for calculating the active duration is normatively defined in .

Having established the active duration, the process for transforming a timed item's inherited time into its transformed time is illustrated below.

An overview of timing model calculations.
(1) The inherited time is converted into a local time by incorporating the start time.
(2) The local time is converted into an active time by incorporating the start delay.
(3) The playback rate and iteration start properties are applied to the active time to produce the scaled active time.
(4) The scaled active time is then converted to an offset within a single iteration: the iteration time.
(5) The iteration time is converted into a directed time by incorporating the playback direction.
(6) Finally, a timing function is applied to the directed time to produce the transformed time.

The first step, calculating the local time is described in . Steps 2 to 4 in the diagram are described in the following sections. Steps 5 and 6 are described in and respectively.

### Calculating the active duration

In order to calculate the active duration we first define the repeated duration as follows:

repeated duration = iteration duration × iteration count

If either the iteration duration or iteration count are zero, the repeated duration is zero.

This clarification is needed since the result of infinity multiplied by zero is undefined according to IEEE 754-2008.

The active duration is calculated according to the following steps:

1. If the playback rate is zero, return Infinity.
2. Otherwise, return repeated duration / abs(playback rate).

### Transforming the local time

#### Calculating the active time

The active time is based on the local time and start delay. However, it is only defined when the timed item should produce an output and hence depends on its fill mode and phase as well as the phase of its parent animation group, if any, as follows,

If the timed item is in the before phase,
The result depends on the first matching condition from the following,
If the timed item has a parent animation group and that parent animation group is in the after phase,
Return null.
If the fill mode is backwards or both,
Return zero.
Otherwise,
Return null.
If the timed item is in the active phase,
The result depends on the first matching condition from the following,
If the timed item has a parent animation group and that parent animation group is in the before phase, and the fill mode of this timed item is none or forwards,
Return null.
If the timed item has a parent animation group and that parent animation group is in the after phase, and the fill mode of this timed item is none or backwards,
Return null.
Otherwise,
Return local time - start delay.
If the timed item is in the after phase,
The result depends on the first matching condition from the following,
If the timed item has a parent animation group and that parent animation group is in the before phase,
Return null.
If the fill mode is forwards or both,
Return the active duration.
Otherwise,
Return null.
Otherwise (the local time is null),
Return null.

#### Calculating the scaled active time

Before the active time can be converted to an iteration time we must factor in the timed item's playback rate and iteration start. The result is called the scaled active time.

In order to calculate the scaled active time we first define the start offset as follows:

start offset = iteration start × iteration duration

If the iteration start is zero, the start offset is zero.

This clarification is needed since the iteration duration may be infinity and the result of infinity multiplied by zero is undefined according to IEEE 754-2008.

The scaled active time is calculated according to the following steps:

1. If the active time is null, return null.
2. Return the scaled active time based on the playback rate as follows,
If the playback rate is less than zero,
Return (active time - active duration) × playback rate + start offset.
If the playback rate is zero,
Return start offset.
Otherwise,
Return active time × playback rate + start offset.

#### Calculating the iteration time

The iteration time is calculated according to the following steps:

1. If the scaled active time is null, return null.
2. If the iteration duration is zero, return zero.
3. If scaled active time - start offset is equal to the repeated duration, and iteration count is not zero, and (iteration count + iteration start) % 1 is zero, return the iteration duration.
4. Otherwise, return scaled active time % iteration duration.

### Calculating the current iteration

The current iteration can be calculated using the following steps:

1. If the scaled active time is null, return null.
2. If the scaled active time is zero, return zero.
3. If the iteration duration is zero, return ceil(iteration start + iteration count) - 1.
4. If the iteration time equals the iteration duration, return iteration start + iteration count - 1.
5. Return floor(scaled active time / iteration duration).

If the iteration duration is infinite, the result of floor(scaled active time / iteration duration) will be zero as defined by IEEE 754-2008.

## Direction control

Timed items may also be configured to run iterations in alternative directions using direction control. For this purpose, timed items have a playback direction parameter which takes one of the following values:

• normal,
• reverse,
• alternate, or
• alternate-reverse.

The semantics of these values are incorporated into the calculation of the directed time which follows.

A non-normative definition of these values is as follows:

normal
All iterations are played as specified.
reverse
All iterations are played in the reverse direction from the way they are specified.
alternate
Even iterations are played as specified, odd iterations are played in the reverse direction from the way they are specified.
alternate-reverse
Even iterations are played in the reverse direction from the way they are specified, odd iterations are played as specified.

### Calculating the directed time

The directed time is calculated from the iteration time using the following steps:

1. If the iteration time is null, return null.
2. Calculate the current direction using the first matching condition from the following list:
If playback direction is normal,
Let the current direction be forwards.
If playback direction is reverse,
Let the current direction be reverse.
Otherwise,
1. Let d be the current iteration.
2. If playback direction is alternate-reverse increment d by 1.
3. There used to be a step here which seemed to be adding special handling for filling when the item ends on a repeat boundary but it seems like that is taken care of by the calcuation of iteration time and current iteration. Is anything actually needed here?

4. If d % 2 == 0, let the current direction be forwards, otherwise let the current direction be reverse.
3. If the current direction is forwards then return the iteration time.

Otherwise, return the iteration duration - iteration time.

## Time transformations

### Scaling the time

It is often desirable to control the rate at which a timed item progresses. For example, easing the rate of animation can create a sense of momentum and produce a more natural effect. Conversely, in other situations such as when modelling a discrete change, a smooth transition is undesirable and instead it is necessary for the timed item to progress in a series of distinct steps.

For such situations Web Animations provides timing functions that scale the progress of a timed item.

Timing functions take an input time fraction and produce a scaled output time fraction.

Example of a timing function that produces an ease-in effect. Given an input timing fraction of 0.7, the timing function scales the value to produce an output time fraction of 0.52.
By applying this timing function, time will appear to progress more slowly at first but then gradually progress more quickly.

Timing functions are applied to an iteration of a timed item.

### Timing functions

A timing function takes an input time fraction in the range [0, 1] and produces an output time fraction whose range is unbounded (i.e. positive and negative infinity are permitted).

Timed items have one timing function associated with them. The default timing function is the linear timing function whose output is identical to its input. The linear timing function can be represented by the string “linear”.

The range of timing functions that may be applied to a given timed item depends on the type of the timed item.

Currently, the set of timing functions allowed on an animation group is not restricted. This has raised concern about complexity of implementation and also complexity of behavior with regards to fill modes. As a result, allowing the full set of timing functions on animation groups is considered at risk.

Alternatives are to either restrict timing functions on animation groups to the linear timing function or to a set of “simple” timing functions that have properties that alleviate some of the concerns with the more complex timing functions.

### Scaling using a cubic Bézier curve

A common method of producing easing effects is to use a cubic Bézier curve to scale the time. The endpoints of the curve are fixed at (0, 0) and (1, 1) while two control points P1 and P2 define the shape of the curve. Provided the x values of P1 and P2 lie within the range [0, 1] such a curve produces a function that is used to map input times (the x values) onto output times (the y values). This arrangement is illustrated below.

A cubic Bézier curve used as a timing function.
The shape of the curve is determined by the location of the control points P1 and P2.
Input time fractions serve as x values of the curve, whilst the y values are the output time fractions.

Some example cubic Bézier timing functions are illustrated below.

The timing functions produced by each of the keyword values associated with cubic Bézier timing functions accepted by the Timing.easing member from the programming interface.

A cubic Bézier timing function is a type of timing function defined by four real numbers that specify the two control points, P1 and P2, of a cubic Bézier curve whose end points are fixed at (0, 0) and (1, 1). The x coordinates of P1 and P2 are restricted to the range [0, 1].

The evaluation of this curve is covered in many sources such as [[FUND-COMP-GRAPHICS]].

A cubic Bézier timing function may be specified as a string using the following syntax (using notation from [[!CSS3-VALUES]]):

<cubic-bezier-timing-function> = ease | ease-in | ease-out | ease-in-out | cubic-bezier(<number> <number> <number> <number>)

The meaning of each value is as follows:

ease
Equivalent to cubic-bezier(0.25, 0.1, 0.25, 1).
ease-in
Equivalent to cubic-bezier(0.42, 0, 1, 1).
ease-out
Equivalent to cubic-bezier(0, 0, 0.58, 1).
ease-in-out
Equivalent to cubic-bezier(0.42, 0, 0.58, 1).
cubic-bezier(<number> <number> <number> <number>)
Specifies a cubic Bézier timing function. The four numbers specify points P1 and P2 of the curve as (x1, y1, x2, y2). Both x values must be in the range [0, 1] or the definition is invalid.

It has been proposed to extend cubic-bezier to allow multiple segments, using syntax such as the following:

            cubic-bezier( [ <number>{6} ; ]* <number>{4} )


(i.e. the curve starts at (0, 0); each segment is defined by six numbers where the start point is the end of the previous segment and the numbers define the two control points and the end point. The last segment is defined by four numbers since the end point is fixed at (1, 1).)

This would provide a simple and compact syntax for tools trying to map arbitrary curves (e.g. bounce functions) to timing functions.

### Timing in discrete steps

It is possible to scale a timed item's timing so that the timed item occurs in a series of discrete steps using a stepping function.

Some example step timing functions are illustrated below.

Example step timing functions. In each case the domain is the input time fraction whilst the range represents the output time fraction produced by the step function.
The first row shows the function for each transition point when only one step is specified whilst the second row shows the same for three steps.

A step timing function is a type of timing function that divides the input time into a specified number of intervals that are equal in duration. The output time, starting at zero, rises by an amount equal to the interval duration once during each interval at the transition point which may be either the start, midpoint, or end of the interval.

In keeping with Web Animations' model of endpoint exclusive interval timing (see ), the output time at the transition point is the time after applying the increase (i.e. the top of the step) with the following exception.

When a transition point coincides with the end of the active interval extra care must be taken to produce the correct result when performing a fill. To achieve this, when a step timing function is applied to a timed item or applied to an animation effect associated with a timed item, an additional before flag is passed. The value of the before flag is determined as follows:

1. If the active time of the timed item is null, the before flag is not set and these steps should be aborted.
2. Determine the current direction using the procedure defined in .
3. If either the current direction is forwards or the timed item playback rate ≥ 0 (but not when both conditions are true), let going forwards be true, otherwise it is false.
4. The before flag is set if the timed item is in the before phase and going forwards is true; or if the timed item is in the after phase and going forwards is false.

When a step timing function is evaluated at a transition point, if the before flag is set the result is the value before applying the increase.

A step timing function may be specified as a string using the following syntax:

<step-timing-function> = step-start | step-middle | step-end | steps(<integer>[, [ start | middle | end ] ]?)

The meaning of each value is as follows:

step-start
Equivalent to steps(1, start);
step-middle
Equivalent to steps(1, middle);
step-end
Equivalent to steps(1, end);
steps(<integer>[, [ start | middle | end ] ]?)
Specifies a step timing function. The first parameter specifies the number of intervals in the function. It must be a positive integer (greater than 0). The second parameter, which is optional, specifies the point at which the change of values occur within the interval. If the second parameter is omitted, it is given the value end.

### Calculating the transformed time

The transformed time is calculated from the directed time using the following steps:

1. If the directed time is null, return null.
2. If the iteration duration is infinity, return the directed time.
3. Let iteration fraction be the result of evaluating directed time / iteration duration unless iteration duration is zero, in which case let iteration fraction be zero.
4. Let scaled fraction be the result of evaluating the timed item's timing function with iteration fraction as the input time fraction.
5. Return the result of evaluating scaled fraction × iteration duration. If the scaled fraction is zero, let the result be zero.

This clarification is needed since the iteration duration may be infinity and the result of infinity multiplied by zero is undefined according to IEEE 754-2008.

## Grouping and synchronization

While it is possible to set the timing properties of timed items individually, it is often useful to synchronize timed items so that they share common timing properties and maintain their temporal relationship. This is achieved using an animation group.

A simple example is illustrated below.

Using groups to share common timing properties.
(a) Shows setting a delay of 5 seconds on individual animations.
(b) Produces the same effect by setting the delay on the group.

When an animation group is directly associated with a player, the timed items associated with the animation group can be seeked, paused, and stopped as a unit.

An animation group is a type of timed item that contains an ordered sequence of zero or more timed items known as child timed items.

At a given moment, a timed item may be a child timed item of at most one animation group known as the parent animation group. The parent animation group cannot be the same timed item as the child timed item itself.

By nesting animation groups it is possible to create hierarchical tree structures. The following terms are used to describe the parts and properties of such structures and are defined in [[!DOM4]]:

Note that in applying these definitions to timed items, the term parent refers exclusively to a parent animation group and does not include the player which with a timed item may be directly associated despite the fact that conceptually the player acts as a parent time source.

The temporal relationship between a child timed item and its parent animation group is incorporated in the definition of inherited time (see ).

### Relationship of group time to child time

The timing of the children of an animation group is based on the timing of the group. Specifically, times for the children are based on the parent's transformed time. With regards to repetition, this means the children operate inside an iteration of the parent.

For example, if an animation group has an iteration count of 2, then the children of of the group will all play twice since they effectively play inside the group's iterations.

Since children of an animation group base their timing on the group's transformed time, when the group repeats, the children play again.

Note that even in this case, the child timed items still have only one active interval. However, as a result of the parent's timing, the active interval is played twice.

If an iteration count is specified for the children of a group as well as for the group itself, the effect is as if the iteration count of the group was multiplied with the iteration count of the children.

Specifying an iteration count of 2 on an animation group and an iteration count of 3 on one of its children results in that child playing 6 times.

A further result of the children of an animation group basing their timing on the group's transformed time is that they cannot animate outside of the group's active interval. This is because the transformed time of a group will not change outside its active interval. This allows groups to clip the playback of their children.

In the first instance, a timed item has a negative delay and an infinite iteration count.
However, when a similar timed item is placed inside an animation group with a specified iteration duration it has the effect of clipping the child timed item's active interval.

Some further consequences of animation group children basing their timing on their parent group's transformed time are:

#### The start time of children of an animation group

The start time of a child timed item of an animation group is zero.

Note that specific types of animation groups may override this definition to provide other kinds of synchronization behavior.

#### The intrinsic iteration duration of an animation group

The intrinsic iteration duration of an animation group is based on the time when the last child timed item completes its active interval and is calculated using the following procedure.

1. Define the end time of a timed item as :

end time = start time + start delay + active duration + end delay
2. The intrinsic iteration duration depends on the number of child timed items as follows,

If the group has no child timed items,
the intrinsic iteration duration is zero.
Otherwise,
1. Let maximum end time be the maximum value after calculating the end time of each child timed item in the group.
2. The intrinsic iteration duration is the result of evaluating max(0, maximum end time).

This definition of the intrinsic iteration duration may be overridden by specific types of animation groups.

### Animation sequences

Specific types of animation groups can be used to provide different kinds of synchronization behavior for their children. This specification defines one additional type of animation group: an animation sequence. Animation sequences arrange the start times of their children so that they run one at a time, in turn.

Compare the two arrangements illustrated below:

Animation groups and animation sequences.
(a) is a regular animation group where all the children run simultaneously.
(b) is an animation sequence where the children run in turn.

Since animation groups can also contain other animation groups, complex synchronization is possible by combining different types of groups as illustrated below.

An animation sequence that contains a regular animation group as a child.
The animation group waits for the previous child of the animation sequence to finish, and then the children of the animation group play simultaneously. After they have finished the next child of the animation sequence plays.

A animation sequence is a type of animation group that schedules its child timed items such that they play in turn following their order in the group. This sequencing is achieved by adjusting the start time of each child timed item in the group.

#### The start time of children of an animation sequence

The start time of a child timed item of an animation sequence is the end time of the child's previous sibling. If the child has no previous sibling the start time is zero.

When the active duration is positive infinity the behavior for calculating the end time of a timed item and the start time of subsequent children follows the usual behavior defined by IEEE 754-2008. As a result, if any of the children of an animation sequence has an infinite active duration, any children that occur later in the sequence will not play.

Similarly, the above definition does not restrict start times to positive values and hence some children may not play due to a negative start delay on children that occur earlier in the group since their active interval may end before the group's start time.

Because the start of the active interval is based on the sum of a timed item's start time and start delay, the active intervals of children of an animation sequence need not run in strict sequence but can be shifted back and forth by using the start delay as shown in the following diagram.

Example of using the start delay on children of an animation sequence to shift their timing so that they overlap (a negative delay) or are spaced apart (a positive delay).

A negative start delay can be used to cause the active interval of two children to overlap. Note that the start delay affects the start time of subsequent children in the group.

#### The intrinsic iteration duration of an animation sequence

The intrinsic iteration duration of a animation sequence is equivalent to the start time of a hypothetical child timed item appended to the group's children calculated according to the definition in unless that produces a negative value, in which case the intrinsic iteration duration is zero.

As a result, if the animation sequence has no child timed items the intrinsic iteration duration will be zero.

## Animations

Animations are a kind of timed item that apply an animation effect or a custom effect to an element or pseudo-element such as ::before and ::first-line [[!SELECT]] referred to as the animation target.

### Calculating the time fraction

Before passing the transformed time of an animation to its animation effect it is converted to a time fraction. The time fraction of a timed item is calculated according to the following steps:

If the iteration duration is zero,

the time fraction is as follows,

If local time < start delay,
Return the result of recalculating the transformed time using an iteration duration of 1.
Otherwise,
1. Let normalized active duration be the result of recalculating the active duration using an iteration duration of 1.
2. Return the result of recalculating the transformed time using a local time of start delay + normalized active duration and an iteration duration of 1.
Otherwise,
Return transformed time / iteration duration unless transformed time is null, in which case return null.

Since timing functions are allowed to produce output times outside the range [0, 1] it is possible that the value calculated for a time fraction also lies outside this range.

## Animation model

The Web Animations animation model takes the time fractions and current iteration values produced by the timing model for a given animation and applies it as the input to the animation's animation effect.

The output of each animation effect is then combined with other animation effects using an animation stack before being applied to the target properties (see ).

## Animation effects

An animation effect takes a time fraction and a current iteration value and uses them to calculate an intermediate animation value for its target properties. Each animation may have at most one animation effect associated with it.

Since the result of an animation effect is based on the time fraction and current iteration value, it is updated whenever the timing model is sampled. Note that changes to the timing model caused by using the programming interface do not cause the animation model (and hence animation effects) to be updated as described in .

### Target properties

Each animation effect can have zero or more associated target properties.

Target properties may be CSS properties or DOM attributes. If a given animation target has an attribute with the same name as a CSS property, any target property is taken to refer to to the CSS property.

If there ever exists a situation where we need to animate an attribute with the same name as a property (other than a presentation attribute [[SVG2]]) then we will need to introduce a disambiguation strategy. Generally, however, such naming should be avoided.

### Procedures for animating properties

In order to animate a target property the following procedures must be defined.

• interpolation — given two target property values Vstart and Vend, produces an intermediate value Vres at a distance of p along the interval between Vstart and Vend such that p = 0 produces Vstart and p = 1 produces Vend. The range of p is (−∞, ∞) due to the effect of timing functions. As a result, this procedure must also define extrapolation behavior for p outside [0, 1].
• addition — given two target property values Va and Vb, returns the sum of the two properties, Vresult. For addition that is not commutative (for example, matrix multiplication) Va represents the first term of the operation and Vb represents the second.
• accumulation — given two target property values Va and Vb, returns the result, Vresult, of combining the two operands such that Vb represents a delta from Va. For accumulation that is not commutative (for example, accumulation of mismatched transform lists) Va represents the first term of the operation and Vb represents the second.

For many types of animation such as numbers or lengths, accumulation is defined to be identical to addition.

A common case where the definitions differ is for list-based types where addition may be defined as appending to a list whilst accumulation may be defined as component-based addition. For example, the filter list values "blur(2)" and "blur(3)", when added together may produce "blur(2) blur(3)", but when accumulated, may produce "blur(5)".

• distance computation — given two target property values Vstart and Vend calculates some notion of scalar distance between the values, distance.

While addition can often be expressed in terms of the same weighted sum function used to define interpolation, this is not always the case. For example, interpolation of transform matrices involves decomposing and interpolating the matrix components whilst addition relies on matrix multiplication.

### Specific animation behaviors

The specific procedures used for animating a given target property are referred to as the property's animation behavior.

The animation behavior of CSS properties is defined by the "Animatable:" line in the summary of the property's definition or in [[CSS3-TRANSITIONS]] for properties that lack a such a line.

The default animation behavior for CSS properties is "as string". Should this be defined here or in CSS Animations Level 4?

For DOM attributes, the animation behavior is defined alongside the attribute definition. Unlike CSS properties, if such a definition is not provided the default animation behavior is “not animatable”.

Following is a series of pre-defined animation behaviors. [[CSS3-TRANSITIONS]] provides further CSS-specific animation behaviors.

For animation behaviors that do not define a specific procedure for addition or which are defined as not additive, the addition procedure is simply Vres = Vb.

For animation behaviors that do not define a specific procedure for accumulation, the accumulation procedure is identical to the addition procedure for that behavior.

For animation behaviors that do not define a specific procedure for distance computation or which are defined as not paceable, the distance computation procedure is simply distance = 1.

#### Not animatable

Some properties are specifically defined as not animatable. For example, properties defining animation parameters are not animatable since doing so would create complex recursive behavior.

Unlike other animation behaviors, no procedures for interpolation, addition and distance computation are defined for properties whose animation behavior is not animatable since these properties should not be modified.

An animation effect that targets a property that is not animatable will still exhibit the usual behavior for a timed item such as occupying time in an animation sequence.

#### Animatable as string

A target property that is animatable as string has the following animation behavior:

#### Animatable as real number

A target property that is animatable as real number has the following animation behavior:

#### Animatable as length, percentage, or calc

A target property that is animatable as length, percentage, or calc has the following animation behavior:

#### Animatable as color

A target property that is animatable as color has the following animation behavior:

• interpolation: as defined in [[CSS3-TRANSITIONS]].
• addition: as with animatable as real number but performed on each RGBA color component in premultiplied space.

Since negative color is not currently supported, clamping of the channel values may be performed upon each addition or once when composition is complete.

• distance computation:
$\mathrm{distance}=\sqrt{{\left({R}_{end}-{R}_{start}\right)}^{2}+{\left({G}_{end}-{G}_{start}\right)}^{2}+{\left({B}_{end}-{B}_{start}\right)}^{2}+{\left({A}_{end}-{A}_{start}\right)}^{2}}$
sqrt((Rend
- Rstart)^2 + (Gend
- Gstart)^2 + (Bend
- Bstart)^2 + (Aend
- Astart)^2)
where <R|G|B|Astart|end> represents the red, green, blue, or alpha channel of Vstart or Vend respectively. Each value is normalized to the [0.0, 1.0] range and expressed in premultiplied color space.

Should we call this “animatable as premultiplied RGBA additive color in sRGB color space” instead?

#### Animatable as transform list

A target property that is animatable as transform list has the following animation behavior:

• interpolation: as defined in Interpolation of Transforms [[CSS3-TRANSFORMS]].
• addition: performed by concatenating transform lists as ‘Va Vb’.
• accumulation: performed by finding the largest initial portion of each list such that the type of the transforms of each pair of elements at the same index in the two sub-lists match. The paired elements in these sub-lists are then accumulated by adding matched numeric components together. The non-matching remainders of the two lists are then added to the result, in the order Va, then Vb.
• distance computation: See issue below

For distance computation we previously defined it as follows:

1. Look only at the first component of the two lists
2. If both are translate → euclidean distance
3. If both are scale → absolute difference
4. If both are rotate → absolute difference
5. If both match but are something else → use linear
6. If they don't match → use matrix decomposition and euclidean distance between translate components

This seems really arbitrary, especially part 5.

Also, looking at only the first component seems odd. Going through each component, working out the distance and then getting the square of the distance also seems much more consistent with what we do elsewhere.

#### Other animation behaviors

The set of animation behaviors defined here may be extended by other specifications. For example, properties with using the <image> type are animated using the interpolation behavior defined in CSS Image Values and Replaced Content [[CSS4-IMAGES]].

There are a bunch of CSS properties for which distance (and in some cases addition) is not defined or which need special handling.

For example,

• font-stretch (an enum but handled like an integer)
• visibility (0 or 1 depending on if endpoints match or not)
• flex-grow and flex-shrink which allow animation only if one of the endpoints is 0)
• value pairs, triples (use square distance)
• rects (use square distance)
• dash arrays (square distance but a bit weird due to percentages)
• shadows (square distance of components)
• filters (undefined)
• background-position (special list handling needed)
• pair lists

Should we define these here or in the CSS Animation 4 spec?

### Intermediate animation values

Given a time fraction, a current iteration, and an underlying value, an animation effect produces an intermediate animation value for each animatable target property. Before being applied to the target properties, these intermediate animation values are composed together using the process defined in .

An intermediate animation value is established by first calculating an unaccumulated animation value and then applying accumulation behavior.

### Unaccumulated animation values

The unaccumulated animation value is the result of evaluating an animation effect for a given target property, time fraction and underlying value independent of the current iteration. The procedure for calculating this value depends on the specific type of animation effect and is defined subsequently (see and ).

### Accumulating animation values

Animation effects may be defined such that as the animation that is applying them repeats, the intermediate animation value builds on the value produced by previous iterations. This behavior is called accumulation.

The accumulation behavior of an animation effect is specified by the animation effect's accumulation operation property. The accumulation operation property takes one of the following two values.

sum

The intermediate animation value produced by the animation effect for a given property is the sum (as calculated using the accumulation procedure of the target property) of the unaccumulated animation value for the given time fraction and the final intermediate animation value of the previous iteration (i.e. the result of evaluating the intermediate animation value with a time fraction of 1, and a current iteration of current iteration - 1).

If the current iteration is zero, the intermediate animation value is just the unaccumulated animation value.

none
The intermediate animation value for the animation effect is just the unaccumulated animation value.

Accumulation behavior is only applied for keyframe animation effects when the composition operation is uniform across all keyframes. For keyframe animation effects where the composition operation varies, an accumulation operation of none is used.

## Combining animations

After calculating the intermediate animation values for an animation effect they are applied to the animation effect's target properties.

Since it is possible for multiple in effect animations to target the same property it is often necessary to combine the results of several animation effects together. This process is called compositing and is based on establishing an animation stack for each property targetted by an in effect animation effect.

After compositing the results of animation effects together, the composited result is combined with other values specified for the target property.

For a CSS target property the arrangement is illustrated below:

Overview of the application of intermediate animation values to their target properties.
The results of animation effects targetting the same property are composited together using an animation stack.
The result of this composition is written to an animation stylesheet that is more important than other stylesheets but less than any !important rules.

For target property that specifies a DOM attribute, the composited result is combined with the value of the attribute specified in the DOM or the lacuna value for that attribute if it is not specified.

For the first part of this operation—combining intermediate animation values that target the same property— it is necessary to determine both how the animation effects associated with the animations are combined with one another, as well as the order in which they are applied, that is, their relative priority.

The matter of how intermediate animation values are combined is governed by the composition operation of the corresponding animation effects.

The relative priority of intermediate animation values is determined by an animation stack established for each animated property.

### The animation stack

Associated with each property targetted by one or more animation effects is an animation stack that establishes the relative priority of the animation effects.

The relative priority of any two animation effects, A and B, within an animation stack is established by comparing the properties of the animations applying A and B as follows:

1. Let the associated player of an animation effect be the player associated with the animation that is applying the animation effect to the property with which this animation stack is associated.
2. Sort A and B by applying the following conditions in turn until the order is resolved,
1. Sort A and B using any custom player priority specified for the associated player of each of A and B so that lower priorities sort first.
2. Sort A and B by the player start time of the associated player of each of A and B converted to the time space of the global clock so that earlier times sort first. Note that this not the adjusted start time.
3. Sort by the player sequence number so that lower sequence numbers sort first.
4. Sort A and B in tree order. (By this point, A and B must have the same player since otherwise the order would have been resolved in the previous step.)

Animation effects that sort earlier have lower priority.

### The custom player priority

Each player has an associated numeric custom player priority that is used to provide high-level control of animation priority for specifications layered on top of Web Animations. The initial value of the custom player priority is zero.

Note that the custom player priority is primarily intended to be used to prioritize animations at a high-level, such as to prioritize animations by type. For example, it can be used to ensure that CSS Animations always override CSS Transitions.

It is possible to control animation priority at a lower-level by setting the player start time appropriately, (possibly after making compensatory adjustments to the start delay of the source content) or influencing the player sequence number by controlling when players are created.

### Calculating the result of an animation stack

In order to calculate the final value of an animation stack, the intermediate animation values of each animation effect in the stack are combined in order of priority from lowest to highest priority.

Each step in the process of evaluating an animation stack takes an underlying value as input.

For each animation effect in the stack, the appropriate intermediate animation value from the animation effect is combined with the underlying value to produce a new value. This resulting value becomes the underlying value for combining the next animation effect in the stack.

The final value of an animation stack, called the composited value, is simply the result of combining the intermediate animation value of the final (highest priority) animation effect in the stack with the underlying value at that point.

### Animation composition

The specific operation used to combine an intermediate animation value with an underlying value is determined by the composition operation of the animation effect that produced the intermediate animation value.

This specification defines three composition operations as follows:

replace
The result of compositing the intermediate animation value with the underlying value is simply the intermediate animation value.

The intermediate animation value is added to the underlying value. For animation behaviors where the addition operation is defined such that it is not commutative, the order of the operands is underlying value + intermediate animation value.

accumulate

The intermediate animation value is accumulated onto the underlying value. For animation behaviours where the accumulation operation is defined such that it is not commutative, the order of the operands is underlying value followed by intermediate animation value.

### Applying the composited result

The process for a applying a composited value depends on if the target property refers to a CSS property or a DOM attribute.

#### Applying the result to a CSS property

Applying a composited value to a CSS target property depends on establishing an animation stylesheet.

The animation stylesheet contains composited animation values and acts with a higher priority than all other stylesheets. However, !important rules from all other stylesheets act with a higher priority than the animation stylesheet. The animation stylesheet is regenerated each time the animation model is updated (see ).

The composited value calculated for a CSS target property is applied using the following process.

1. Calculate the base value of the property as the value generated for that property by computing the used value [[!CSS21]] for that property in the absence of the animation stylesheet.
2. Establish the animation stack for the property (see ).
3. Calculate the composited value of the animation stack passing in the base value of the property as the initial underlying value (see ).
4. Insert the composited value into the animation stylesheet.

#### Applying the composited result to a DOM attribute

DOM attributes are, unless otherwise specified, not animatable. For each attribute that has a specific animation behavior associated with it, an attribute value to use when the attribute is not specified or in error must be defined, referred to as the lacuna value. For example, SVG2 ([[SVG2]]) defines lacunae values for its attributes.

The composited value calculated for a DOM attribute target property is applied using the following process.

1. Let the base value of the property be the value specified for attribute in the DOM or, if the attribute value is not specified in the DOM, the lacuna value for that attribute.
2. Establish the animation stack for the property (see ).
3. Calculate the composited value of the animation stack passing in the base value of the attribute as the initial underlying value (see ).
4. Record the composited value as the animated attribute value of the attribute.

The animated attribute value does not replace the value of the attribute in the DOM although it may be accessible via some other interface. For all intents and purposes other than interaction with DOM interfaces, user agents must treat the animated attribute value as the attribute value.

## Keyframe animation effects

A keyframe animation effect is an animation effect that produces intermediate animation values for its target properties by interpolating between a series of property values positioned at fractional offsets.

Each set of property values indexed by an offset is called a keyframe.

The offset of a keyframe is a value in the range [0, 1] or the special value null. The list of keyframes for a keyframe animation effect is loosely sorted by offset which means that for each keyframe in the list that has a keyframe offset that is not null, the offset is greater than or equal to the offset of the previous keyframe in the list with a keyframe offset that is not null, if any.

The behavior when keyframes overlap or have unsupported values is defined in .

Each keyframe also has a timing function associated with it that is applied to the period of time between the keyframe on which it is specified and the next keyframe in the list. The timing function specified on the last keyframe in the list is never applied.

In addition to the composition operation specified on the animation effect, each keyframe may also have an associated composition operation that is applied to all values specified in that keyframe. If no composition operation is specified for a keyframe, the composition operation specified for the animation effect is used.

### Spacing keyframes

It is often useful to be able to provide a series of property values without having calculate the keyframe offset of each value in time but instead to rely on some automatic spacing.

For example, rather than typing:

elem.animate([ { color: 'blue', offset: 0 },
{ color: 'green', offset: 1/3 },
{ color: 'red', offset: 2/3 },
{ color: 'yellow', offset: 1 } ], 2000);


It should be possible to type the following and allow the user agent to calculate the offset of each keyframe:

elem.animate([ { color: 'blue' },
{ color: 'green' },
{ color: 'red' },
{ color: 'yellow' } ], 2000);


Web Animations provides spacing modes for this purpose. The default spacing mode for keyframe animation effects is “distribute” which produces the result described above.

The other spacing mode, “paced”, is useful when it is desirable to maintain an even rate of change such as for motion path animation.

For example, consider the following animation:

elem.animate([ { left: '0px' },
{ left: '-20px' },
{ left: '100px' },
{ left: '50px' } ], 1000);


The resulting value of the left property is illustrated below:

The animated value of the left property over time when applying the distribute spacing mode. The values are evenly spaced in time but the rate of change differs for each segment as indicated the varying slope of the graph.

We can use the paced spacing mode as follows:

elem.animate(
new KeyframeEffect([ { left: '0px' },
{ left: '-20px' },
{ left: '100px' },
{ left: '50px' } ], { spacing: "paced" }), 1000);


The result is illustrated below:

The animated value of the left property over time when applying the paced spacing mode. The absolute value of the slope is graph is equal for all segments of the animation indicating a constant rate of change.

It is also possible to combine fixed keyframe offsets with spacing modes as follows:

elem.animate(
new KeyframeEffect([ { left: '0px' },
{ left: '-20px' },
{ left: '100px', offset: 0.5 },
{ left: '50px' } ], { spacing: "paced" }), 1000);


The result is illustrated below:

The animated value of the left property over time when applying the paced spacing mode and a fixed keyframe offset that puts the 100px value at 0.5. The slope of the graph is equal for the first two segments but changes for the last segment in order to accommodate the fixed offset.

Before calculating animation values from a keyframe animation effect, an absolute value must be computed for the keyframe offset of each keyframe with a null offset. The values computed depend on the keyframe spacing mode specified for the keyframe animation effect. The keyframe spacing modes are:

distribute
Indicates that keyframes with a null keyframe offset null are positioned so that the difference between subsequent keyframe offsets are equal.
paced
Indicates that keyframes with a null keyframe offset null are positioned so that the distance between subsequent values of a specified paced property are equal. The distance is calculated using the distance computation procedure defined by the animation behavior associated with the paced property.

## Applying spacing to keyframes

We define a generic procedure for evenly distributing a keyframe, keyframe, between two reference keyframes, start and end, whose keyframe offsets are not null, as follows:

1. Let offsetk be the keyframe offset of a keyframe k.
2. Let n be the number of keyframes between and including start and end minus 1.
3. Let index refer to the position of keyframe in the sequence of keyframes between start and end such that the first keyframe after start has an index of 1.
4. Set the keyframe offset of keyframe to offsetstart + (offsetendoffsetstart) × index / n.

The computed keyframe offset values of each keyframe with a null keyframe offset are determined using the following procedure.

1. Let keyframes refer to the list of keyframes associated with the keyframe animation effect.
2. If keyframes contains more than one keyframe and the keyframe offset of the first keyframe in keyframes is null, set the keyframe offset of the first keyframe to 0.
3. If the keyframe offset of the last keyframe in distributed keyframes is null, set its keyframe offset to 1.
4. For each pair of keyframes A and B where:

calculate the keyframe offset of each keyframe between A and B depending on the keyframe spacing mode as follows:

If the spacing mode is paced,
1. Define a keyframe as paceable if it contains a value for the paced property.
2. Let paced A be the first keyframe in the range [A, B] that is paceable, if any.
3. Let paced B be the last keyframe in the range [A, B] that is paceable, if any.
4. If there is no paced A or paced B let both refer to B. Note that in this case, the spacing behavior degenerates to distribute spacing.
5. For each keyframe in the range (A, paced A] and [paced B, B), apply the procedure for evenly distributing a keyframe using A and B as the start and end keyframes respectively.
Yes, this is correct. We want, index and n in that procedure to reflect all the keyframes between A and B, not just the keyframes between, for example, A and spaced A.
6. For each keyframe in the range (paced A, paced B) that is paceable:
1. Let distk represent the cumulative distance to a keyframe k from paced A as calculated by applying the distance computation defined by the animation behavior of the paced property to the values of the paced property on each pair of successive paceable keyframes in the range [paced A, k].
2. Set the offset of k to offsetpaced A + (offsetpaced Boffsetpaced A) × distk / distpaced B
7. For each keyframe in the range (paced A, paced B) that still has a null keyframe offset (because it is not paceable), apply the procedure for evenly distributing a keyframe using the nearest keyframe before and after the keyframe in question in keyframes that has a keyframe offset that is not null, as the start and end keyframes respectively.
Otherwise,
Apply the procedure for evenly distributing a keyframe to each keyframe in the range (A, B) using A and B as the start and end keyframes respectively.

Note that although the above procedure defines computing keyframe offsets in terms of overwriting null values, user agents that implement the programming interface are required to maintain the original null values as well as calculating the computed offsets. This is because the getFrames method of the KeyframeEffect interface returns keyframe offsets both before and after applying spacing.

The above algorithm is quite complex. It attempts to cover all possible combinations of input where keyframe offsets and or paced property values may be missing. Furthermore, it attempts to do this in a way that degenerates consistently and also allows the author to combine fixed offsets with either pacing or distribute spacing. We await implementation experience to determine if the complexity is justified.

### The unaccumulated animation value of a keyframe animation effect

The unaccumulated animation value of a single property referenced by a keyframe animation effect as one of its target properties, for a given time fraction and underlying value is calculated as follows.

1. Let target property be the property for which the unaccumulated animation value is to be calculated.
2. If animation behavior of the target property is not animatable abort this procedure since the effect cannot be applied.
3. Let time fraction be the time fraction for which the unaccumulated animation value is to be calculated.
4. Let underlying value be the current underlying value for target property.
5. Define the neutral value for composition as a value which, when combined with an underlying value using the add composition operation, produces the underlying value.
6. Let property-specific keyframes be a copy of the list of keyframes specified on the effect.
7. Remove any keyframes from property-specific keyframes that do not have a property value for target property.
8. If property-specific keyframes is empty, return underlying value.
9. If there is no keyframe with a keyframe offset of 0, create a new keyframe with a keyframe offset of 0, a property value set to the neutral value for composition, and a composition operation of add, and add it to the beginning of property-specific keyframes.
10. Similarly, if there is no keyframe with a keyframe offset of 1, create a new keyframe with a keyframe offset of 1, a property value set to the neutral value for composition, and a composition operation of add, and append it to the end of property-specific keyframes.
11. Iterate over each keyframe in property-specific keyframes and for each keyframe, if:
perform the following steps:
1. Let composition operation to use be the composition operation of keyframe, or if it has none, the composition operation of this keyframe animation effect.
2. Let value to combine be the property value of target property specified on keyframe.
3. Replace the property value of target property on keyframe with the result of combining underlying value (Va) and value to combine (Vb) using the composition operation to use, applying the animation behavior of target property.
12. If time fraction < 0 and there is more than one keyframe in property-specific keyframes with a keyframe offset of 0, return the property value for target property of the first keyframe in property-specific keyframes.
13. If time fraction ≥ 1 and there is more than one keyframe in property-specific keyframes with a keyframe offset of 1, return the property value for target property of the last keyframe in property-specific keyframes.
14. Otherwise, let start keyframe be the last keyframe in property-specific keyframes whose keyframe offset is less than or equal to time fraction and less than 1. If there is no such keyframe (because, for example, the time fraction is negative), let start keyframe be the last keyframe whose keyframe offset is 0.

Does the condition beginning “If there is no such keyframe…” ever happen?
There is always at least one keyframe at zero because we synthesize one earlier if there is not. And if time fraction is less than zero then we deal with it above, so there should always be a keyframe with offset ≤ time fraction by this point right?.

15. Let end keyframe be the next keyframe in property-specific keyframes after start keyframe.
16. Let start offset be the keyframe offset of start keyframe.
17. Let end offset be the keyframe offset of end keyframe.
18. Let interval distance be the result of evaluating (time fraction - start offset) / (end offset - start offset)
19. Return the result of interpolating between start keyframe and end keyframe by using the interpolation procedure defined by the animation behavior of the target property using interval distance as the interpolation parameter p and the property values of target property specified on start keyframe and end keyframe as Vstart and Vend repsectively.

Note that this procedure assumes the following about the list of keyframes specified on the effect:

• Each keyframe has a specified keyframe offset in the range [0, 1].
• The list of keyframes is sorted in ascending order by keyframe offset.
• Each specified property value is a valid and supported value.
• For a given property, there is a most one specified property value on each keyframe.

It is the responsibility of the user of the model (for example, a declarative markup or programming interface) to ensure these conditions are met.

For example, for the programming interface defined by this specification, these conditions are met by applying the normalization defined in and resolving null keyframe offsets by applying spacing behavior.

Note that this procedure permits overlapping keyframes. The behavior is that at the point of overlap the output value jumps to the value of the last defined keyframe at that offset. For overlapping frames at 0 or 1, the output value for time fractions less than 0 or greater than or equal to 1 is the value of the first keyframe or the last keyframe in keyframes respectively.

In the presence of certain timing functions, the input time fraction to an animation effect is not limited to the range [0, 1]. Currently, however, keyframe offsets are limited to the range [0, 1] and property values are simply extrapolated for input time fractions outside this range.

We have considered removing this restriction since some cases exist where it is useful to be able to specify non-linear changes in property values at time fractions outside the range [0, 1]. One example is an animation that interpolates from green to yellow but has an overshoot timing function that makes it temporarily interpolate ‘beyond’ yellow to red before settling back to yellow.

While this effect could be achieved by modification of the keyframes and timing function, this approach seems to break the model's separation of timing concerns from animation effects.

It is not clear how this effect should be achieved but we note that allowing keyframe offsets outside [0, 1] may make the currently specified behavior where keyframes at offset 0 and 1 are synthesized as necessary, inconsistent.

## Motion path animation effects

A motion path animation effect is an animation effect that produces animation values for the transform target property of an animation target such that it follows a geometric curve commonly referred to as a “motion path”.

The motion path of a motion path animation effect is defined by an SVG Path, as specified by SVG [[!SVG2]]. A motion path consists of a list of path commands (see path data [[!SVG2]]).

Amongst the different types of path commands, we define orientation path commands as moveto commands and bearing commands. All types of path commands that are not orientation path commands are referred to as drawing path commands.

The automatic rotation flag of a motion path animation effect, if set, specifies that the unaccumulated animation value generated by the motion path animation effect produces a rotation that matches the directional tangent vector of the motion path.

The rotation angle parameter of a motion path animation effect specifies a constant rotation that applies to the target transform in addition to any rotation generated by setting the automatic rotation flag.

## Distance along a path

The procedure used for calculating the length of a path or a subsection is provided by the definition of distance along a path in SVG [[!SVG2]].

## Spacing motion paths

The following properties control the rate of progress of a motion path animation effect:

spacing mode

Specifies the strategy used for determining the offset of each spacing point or path command when not specified by a point offset. The possible spacing modes are identical to those defined for keyframe animation effects (see ).

Note that a spacing mode of distribute has no effect if point offsets are specified. This is because spacing between point offsets always uses paced spacing mode.

spacing points

An optional sequence of real numbers in the range [0.0, 1.0] that correspond to fractions of the total path length. The animation effect produces animation values such that the animation target moves backwards and forwards along the motion path following the sequence indicated by these points.

Furthermore, the point on the motion path indicated by each such number forms a handle that may be associated with a point offset or positioned by the spacing mode.

point offsets

An optional ordered sequence of real numbers in the range [0.0, 1.0] that specifies the time fraction when the corresponding spacing point, or, if spacing points are not provided, drawing path command, should be visited.

If specified, the first value in the sequence must be 0.0 and the last value must be 1.0. There must be as many items in the sequence of point offsets as in the sequence of spacing points, if provided. If a sequence of spacing points is not provided, the number of items in point offsets must equal the number of drawing path commands in the motion path plus one.

point easing

An optional ordered sequence of timing functions that specify the easing behavior between each pair of spacing points, or, if spacing points are not provided, between each pair of drawing path commands.

If specified, there must be as many items as in the sequence of spacing points minus one, if provided. If a sequence of spacing points is not provided, the number of items in point easing must equal the number of drawing path commands in the motion path.

Note that the above descriptions of the length of each list represent the requirements of the model. Users of the model such as markup or programming interfaces may fulfil these requirements, for example, by defining padding behavior or error handling.

Need a diagram here showing how the different combinations work.

## Applying spacing to motion paths

The end result of applying spacing is:

The sequence of effective spacing points is determined by following the steps associated with the first matching condition from below:

If there are no drawing path commands,
Let effective spacing points be an empty sequence.
If spacing points is specified,
Let effective spacing points refer to spacing points.
Otherwise,
Perform the following steps:
1. Let effective spacing points be a sequence consisting of the single element 0.
2. For each drawing path command in path commands, append to effective spacing points a number equal to the distance along a path up to the point at the end of the given path command, divided by the total path length.

Having determined the effective spacing points, the sequence of effective point offsets is determined by following the steps associated with the first matching condition from below:

If there are no drawing path commands,
Let effective point offsets be an empty sequence.
If point offsets is specified,
Let effective point offsets refer to point offsets.
If the spacing mode is distribute,
Perform the following steps:
1. Let effective point offsets be a sequence of equal length to effective spacing points.
2. Let n be the number of elements in effective point offsets minus one.
3. Let k represent an index in the range [0, n].
4. Set the value of each point in effective point offsets so that the point at index k is equal to k / n.
Otherwise,
Perform the following steps:
1. Let effective point offsets be a sequence of equal length to effective spacing points.
2. Let n be the number of elements in effective point offsets minus one.
3. Let k represent an index in the range [0, n].
4. Let point(k) represent the value of effective spacing points at index k.
5. Set the value of each point in effective point offsets so that the value at index k is defined by the following formula:
• For k = 0, offset = 0
• For k = 1..n, offset =
$\frac{\underset{i=1}{\overset{k}{\Sigma }}\left|\mathrm{point}\left(i\right)-\mathrm{point}\left(i-1\right)\right|}{\underset{i=1}{\overset{n}{\Sigma }}\left|\mathrm{point}\left(i\right)-\mathrm{point}\left(i-1\right)\right|}$
[ \sum_{i=1}^k | point(i)-point(i-1) | ] / [ \sum_{i=1}^n | point(i)-point(i-1) | ]
When effective spacing points is a sequence of monotonically increasing points beginning with 0 and ending with 1 (or, in fact, any time the sum of distances between effective spacing points is equal to 1), effective point offsets will mirror effective spacing points.

The effective point easing is simply the specified point easing. If point easing is not set, the effective point easing is a sequence of linear timing functions equal in length to the number of drawing path commands in the motion path.

## Determining the path fraction

The path fraction for a given time fraction, progress, is determined using the following procedure:

1. If effective point offsets is empty, let path fraction equal time fraction and abort these steps.
2. If effective point offsets has only one item, let path fraction equal the value of the one item in effective spacing points and abort these steps.
Effective point offsets can only have one item if spacing points has exactly one item. In this case, the effective points offsets will always be a list containing just the value 0.
3. If progress ≥ 1, let the path fraction equal the value of the last item in effective point offsets and abort these steps.
4. If progress < 0, let the path fraction equal the value of the first item in effective point offsets and abort these steps.
5. Let start index and end index represent the zero-based indices of the last pair of successive values in effective point offsets such that start offsetprogressend offset.
6. Let interval fraction be the ratio of the difference between progress and the offset at start index, and the difference between the offset at end index and the offset at start index.
7. Let scaled interval fraction be the result of applying the timing function from effective point easing at index start index with interval fraction as the input.
8. Let segment start and segment end be the values in effective spacing points at the indicies start index and end index respectively.
9. Let the path fraction be the result of evaluating the following formula: scaled interval fraction * (segment end - segment start) + segment start.

### The unaccumulated animation value of a motion path animation effect

The unaccumulated animation value of a motion path animation effect for a given time fraction and underlying value is given by the following process:

1. Let distance be the path fraction for the given time fraction.
2. Let displacement be the point located distance along the motion path using the definition for distance along a path.

If distance indicates a point on the path that is coincidental with one or more orientation path commands, displacement is the point after all orientation path commands (this will be the start of the next drawing path command if there is one).

3. Let the translation component be the translation transform required to transform the point at the start of motion path to displacement.
4. Calculate the rotation component according to the first match condition from the following:
If the automatic rotation flag is set,
the rotation component is a transform representing the rotation angle.
Otherwise,
the rotation component is a transform representing the sum of:
• the angle of the tangent vector at displacement, and
• the rotation angle.

When calculating the angle of the tangent vector, if there are no drawing path commands in the motion path, the the angle should be taken to be zero.

The original text for this section contained the following qualifications but I'm not sure how meaningful they are:

• For continuous path commands (all elements except moveto), the angle of the tangent vector for the purpose of these calculations is defined to be an integer multiple of 2π different from the value given by standard mathematical formulae for tangents to curves in 2 dimensional space.
• For moveto path commands, which are discontinuous, the angle of the tangent vector for the purpose of these calculations is always an integer multiple of 2π.
• The initial value of the angle of the tangent vector is computed using the first element of the curve, and is always in the range [0, 2π).
• Single continuous path commands must never produce tangent vector angles that are discontinuous over their defined region. This implies that a single unique solution is available for all points on continuous path commands.
• When computing angles after discontinuous or non-smooth jumps, multiple possible solutions may be available. These solutions will differ by integer multiples of 2π. In such cases the solution that lies closest to the previous tangent angle is used.
5. Let the transform value be the result of by constructing a transform list consisting of the translation component followed by the rotation component.
What's the value in keeping these separate? Shouldn't we collapse them?
6. The unaccumulated animation value of the motion path animation effect is the result of applying the composition operation of the effect, passing transform as the intermediate animation value and underlying value as the value to combine with.

Need to describe how transform-origin is applied.

### Custom effects

In some situations the animation effects provided by Web Animations may be insufficient. For example, the animation effects defined here are only able to target certain CSS properties. They are unable, therefore, to modify the currentScale property of an SVG element to smoothly zoom the viewport without affecting the document content.

In such cases, where the provided animation effects do not provide needed functionality, an effect defined by script may be used. Such custom effects receive a time fraction and current iteration from the timing model and are responsible for producing an effect corresponding to the specified time.

Using an effect defined in script it is possible to animate not only otherwise un-animatable attributes and properties, but potentially anything that is accessible via script, including even producing audio or creating vibrations.

For example, using a custom effect that draws to a canvas element, it is possible to produce a complex animated effect featuring patterns that may be difficult to create using CSS or SVG. Compared to using the WindowAnimationTiming interface, this approach ensures the animation is frame-rate independent and can be paused, reversed, eased with timing effects, accelerated, synchronized with other animations, and be controlled in the same manner as any other Web Animations animation without any additional programming.

A custom effect is an author-defined programming callback that is passed timing information whenever a sample is performed.

#### Execution order of custom effects

Since custom effects, unlike animation effects, are not limited to a single target property, the steps for assessing their order of execution differs from animation effects.

Custom effects are executed after all animation effects have completed and applied their result to their targets (see ).

Need to define this more precisely. Are styles flushed? Presumably they are. Can we suspend reflow for the duration of executing the script-based animation effects and just do it once afterwards?

Within the set of custom effects, the order of execution is the same as that defined for animation effects in . Items sorted earlier are executed before those sorted later.

## Programming interface

In addition to the abstract model described above, Web Animations also defines a programming interface to the model. This interface can be used to inspect and extend animations produced by declarative means or for directly producing animations when a procedural approach is more suitable.

### The AnimationTimeline interface

Timelines, including the document timeline are represented in the Web Animations API by the AnimationTimeline interface.

Returns the time value for this timeline or null if this timeline is not started.

AnimationPlayer play()

Creates a new AnimationPlayer object associated with this timeline that is scheduled to start at currentTime.

The timeline attribute of the newly-created AnimationPlayer object will be set to this object.

Similarly, the start time of the newly created player will be set to the value of this object's currentTime attribute at the moment the method was called.

The setting of the source attribute is described below under the description of the source parameter.

The currentTime attribute of the AnimationPlayer object is a calculated value described in .

The playbackRate and paused attributes take on their default values as described in the definitions of the playback rate and paused state properties of player objects.

optional TimedItem? source = null

The source content to assign to the newly-created AnimationPlayer object.

The source attribute of the created AnimationPlayer is set by following the procedure defined for updating that attribute. As a result, if source is already associated with a player, it will be disassociated first before being associated with the new AnimationPlayer.

sequence<AnimationPlayer> getAnimationPlayers()

Returns the set of AnimationPlayer objects associated with this timeline that have associated source content which is current.

The returned list is sorted in increasing order by player sequence number.

double? toTimelineTime (double otherTime, AnimationTimeline other)

Returns the time value, otherTime, from another AnimationTimeline also tied to the global clock, other, converted to a time value relative to this timeline's zero time.

Returns null if:

Note that unlike currentTime, this method may return a negative time value if otherTime occurred prior to this timeline's zero time.

Furthermore, negative values for otherTime are also allowed.

If this timeline records the time value of the global clock at its zero time as global clock offset, and so does other as other global clock offset, then the result of this method is simply:

other global clock offset + otherTime - global clock offset

Exceptions:

DOMException of type InvalidNodeTypeError
Raised if other is a timeline that is not tied to the global clock.

The reason for choosing InvalidNodeTypeError here is that DOM4 describes it as meaning, "The supplied node is incorrect or has an incorrect ancestor for this operation." In this case the error is because other does not have the global clock as an ancestor so it seems appropriate.

double? toTimelineTime (Event event)

Returns the number of milliseconds between when event was fired and this timeline's zero time.

Since the timeStamp attribute of the Event interface specified in [[DOM-LEVEL-3-EVENTS]] is not guaranteed to be monotonically increasing, implementations SHOULD record alongside each event the time value of the global clock when the event is dispatched so that it can be converted to an accurate time value here.

Unlike currentTime, this method may return a negative time value if the event was fired prior to this timeline's zero time.

Returns null if this timeline is not started.

This might be deferred to a later version.

### The AnimationPlayer interface

Players are represented in the Web Animations API by the AnimationPlayer interface.

attribute TimedItem? source

The source content associated with this player.

A player can only be associated with at most one timed item, and likewise, a timed item can only be associated with at most one player. In order to maintain these invariants, on setting this value, the following procedure is performed:

1. Let old value be the current value of the source attribute.
2. Let new value be the value to set.
3. If new value is the same object as old value, return.
4. If old value is not null, disassociate old value from this player.
5. If new value is not null, perform the steps associated with the first matching condition of the following:
If new value has no parent group and is associated with a player,
disassociate new value from its player.
If new value has a parent group,
remove new value from its parent group by calling new value.remove().
Otherwise,
do nothing.
6. Associate new value with this player.
7. Set the source attribute to new value.
The timeline associated with this player.
attribute double startTime
Returns the adjusted start time of this player. Setting this attribute updates the player start time (and consequently the adjusted start time) using the procedure defined in .
attribute double currentTime
The effective current time of this player. Setting this attribute follows the procedure defined in .
attribute double playbackRate
The playback rate of this player. Setting this attribute follows the procedure defined in .
The paused state of this player.
Returns true if this player has reached or passed the end of its source content in its current playback direction. This corresponds to when the player is limited.
void cancel()
Set source to null and clears all effects associated with the previous source content.
We need to make sure, for example, that any custom effects get called with a null sample time so they can remove their effects. This applies to manually setting source to null as well so we should define this behavior there.
void finish()

Seeks the player to the end of the source content in the current direction as follows:

If player playback rate < zero,
Seek the player so its current time is zero.
If player playback rate equals zero,
Do nothing.
If player playback rate > zero,
Seek the player so its current time is equal to the end time of the source content or zero if there is no source content associated with this player..

Exceptions:

DOMException of type InvalidStateError
Raised if the end time of this player's source content is infinity and the player playback rate is > zero.
void play()

Unpauses the player and rewinds if it has finished playing using the following procedure:

1. Set the paused state of the player to false using the procedure defined in .
2. If source content is associated with the player, adjust the current time of the player as follows:
If player playback rate > 0; and either current time < zero or current timesource content's end time,
Seek to time zero.
If player playback rate < 0; and either current time ≤ zero or current time > source content's end time,
Seek to the source content's end time.
Otherwise,
Do nothing.
3. Set the player's finished flag to false.
void pause()
Set the paused state of this player to true using the procedure defined in .
void reverse()

Inverts the playback rate of this player and seeks to the start of the source media if it has finished playing in the reversed direction using the following procedure.

1. If the player playback rate is zero, abort these steps.
2. If source content is associated with the player, adjust the current time of the player as follows:
If player playback rate > zero and effective current time > source content's end time,
Seek to the source content's end time.
If player playback rate < zero and effective current time < zero,
Seek to time zero.
Otherwise,
Do nothing.
3. Set the player playback rate to -player playback rate following the steps in .
4. Set the paused state of the player to false.

Is this unpausing behavior correct?

Note that unlike play(), the player's finished flag is not explicitly reset here since that behavior is performed by the procedure for updating the player playback rate defined in .

// Event callbacks
attribute EventHandler onfinish

The event handler for the finish event.

Note that the EventHandler callback interface type is defined in [[!HTML5]].

### The TimedItem interface

Timed items are represented in the Web Animations API by the TimedItem interface.

// Playback state

The local time of this timed item.

localTime will be null if this timed item is not associated with a player or if it has a parent animation group that is not in effect.

The current iteration index beginning with zero for the first iteration.
// Specified timing

Returns the input timing properties specified for this timed item. This is comparable to the specified style on an Element, elem.style.

Should we make this writeable? Then you could do:

                animA.timing = animB.timing;


Doing so would probably also involve defining Timing.clone and a constructor for Timing.

Representing these parameters has been a particularly contentious topic.

The current arrangement:

• requires defining both a Timing interface and a TimingInput dictionary type which increases the API surface area somewhat
• means that setting the value occurs at a different place (anim.timing.duration) to reading the value (typically, anim.duration)
• opens up questions about whether Timing objects should be share-able or not
• uses a union of a string and a double to represent a duration which opens up questions about whether strings such as "3s" should be allowed (and allowing them makes walking the tree more complex).

However, it separates "specified" timing from "computed" timing which some consider advantageous.

The only situation where calculated values and input values differ is for duration.

One alternative that has been proposed is to introduce a Duration interface as follows:

interface TimedItem {
// Timing
attribute double   delay;
attribute FillMode fill;
attribute Duration duration;
attribute double   playbackRate;
// ...

// Scheduled time
};

interface Duration {
double    ms;
DOMString string;
}


Usage is as follows:

 var specifiedDur  = anim.duration.string; // "auto"
var calculatedDur = anim.duration.ms; // 5000

// Update duration to 3s
anim.duration.ms = 3000;
// anim.duration.string -> "3s"

// Update duration to 3s (alt.)
anim.duration.string = "3s";
// anim.duration.ms -> 3000

// Reset to auto
anim.duration.string = "auto";
// anim.duration.ms -> 5000


Your feedback is most welcome at public-fx@w3.org, subject [web-animations] ….

// Calculated timing

The start time of this timed item in milliseconds. This is the time at which the parent animation group, if any, has scheduled this child to run within its transformed time space, that is, the timed item's inherited time space.

The start of the active interval is based on the sum of the start time and start delay.

The iteration duration of this timed item.

Unlike the duration attribute of the Timing interface or TimingInput dictionary, this attribute returns the calculated value of the iteration duration. If timing.duration is the string auto or any unsupported value, this attribute will return the current calculated value of the intrinsic iteration duration.

This value may be changed by setting the duration attribute of the timing member of this interface.

The active duration of this timed item.

The end time of the timed item expressed in milliseconds in inherited time space. This corresponds to the end of the timed item's active interval plus any end delay.

// Timing hierarchy

The parent animation group of this timed item or null if this timed item does not have a parent animation group.

Should this be parentGroup?
The previous sibling of this timed item.
The next sibling of this timed item.
void before (TimedItem... items)

Inserts items before this timed item.

1. If there is no parent animation group, terminate these steps.
2. If any of the timed items in items is an inclusive ancestor of this timed item throw a HierarchyRequestError exception and terminate these steps.
3. Insert items before this timed item.

Note that this definition precludes the following usage since item is an inclusive ancestor of itself:

                item.before(item); // throws HierarchyRequestError

void after (TimedItem... items)

Inserts items after this timed item.

1. If there is no parent animation group, terminate these steps.
2. If any of the timed items in items is an inclusive ancestor of this timed item throw a HierarchyRequestError exception and terminate these steps.
3. Let reference child be the next sibling of this timed item not in items.
4. Insert items before reference child.
void replace (TimedItem... items)

Replaces this TimedItem with the passed in items.

1. If there is no parent animation group, terminate these steps.
2. If any of the timed items in items is an inclusive ancestor of the parent animation group throw a HierarchyRequestError exception and terminate these steps.
3. Let reference child be the next sibling of this timed item not in items.
4. Remove this timed item from its parent animation group.
5. Insert items before reference child.
void remove ()
Removes this timed item from its parent animation group or player.
// Associated player

The player with which this timed item is associated, if any. This object can be used to perform play control such as pausing or rewinding on this timed item and all other timed items in the same hierarchy.

This will be null if this timed item is not associated with a player.

Feedback has been provided that suggests this reference causes the relationship between AnimationPlayers and TimedItems to be circular, which confuses the model. The player attribute should be considered at risk unless a strong use case for the reference arises.

### The Timing interface

Timing parameters for a TimedItem are collected together under the Timing type.

attribute double delay

The start delay which represents the number of milliseconds from a timed item's start time to the start of the active interval.

Now that we have endDelay, should we change this back to startDelay?

attribute double endDelay

The end delay which represents the number of milliseconds from the end of a timed item's active interval until the start time of any timed item that may follow, for example, in an animation sequence.

attribute FillMode fill

The fill mode as specified by one of the FillMode enumeration values.

When performing timing calculations the special value auto is expanded to one of the fill modes recognized by the timing model as follows,

If the timed item to which the fill mode is being is applied is an animation,
Use none as the fill mode.
Otherwise,
Use both as the fill mode.
attribute double iterationStart

The timed item's iteration start property.

A finite real number greater than or equal to zero representing the number of iterations into the timed item at which to begin. For example, a value of 0.5 would cause the timed item to begin half-way through the first iteration.

Values less than zero are clamped to zero for the purpose of timing model calculations.

Note that the value of iterations is effectively added to the iterationStart such that a timed item with an iterationStart of ‘0.5’ and iterations of ‘2’ would still repeat twice however it would begin and end half-way through the timed item's iteration interval.

Setting the iterationStart to a value greater than or equal to one is typically only useful in combination with an animation effect that has an accumulate property of ‘accumulate’.

attribute unrestricted double iterations

The timed item's iteration count property.

A real number greater than or equal to zero (including positive infinity) representing the number of times to repeat the timed item.

Values less than zero and NaN values are treated as the value 1.0 for the purpose of timing model calculations.

attribute (unrestricted double or DOMString) duration

The iteration duration which is a real number greater than or equal to zero (including positive infinity) representing the time taken to complete a single iteration of the timed item.

The string value auto is used to indicate that the iteration duration reflects the timed item's intrinsic iteration duration.

Real numbers less than zero, NaN values, and strings other than the lowercase value auto are treated the same as auto for the purpose of timing model calculations.

Should we allow strings such as "3s" here? i.e. a CSS <time>. It might be useful for readability but introduces complexity when handling this member (need to test the type, then possibly parse the string). It also introduces the issue of whether we should parse a full clock value.

attribute double playbackRate

The timed item's playback rate property.

This is a multiplier applied to the local time potentially causing the item to run at a different rate to its natural speed.

attribute PlaybackDirection direction

The playback direction of the timed item as specified by one of the PlaybackDirection enumeration values.

attribute DOMString easing

The timing function used to scale the time to produce easing effects.

The syntax of the string is defined by the following production:

Unrecognized string values or values that correspond to a timing function that is not supported for the type of timed item to which this property is applied are treated as if the linear keyword was specified for the purpose of timing model calculations.

In future we may extend this so that it is possible to query the individual functions in the string. It may be possible to do this by extending this attribute using some stringifier magic, or else we could just add easingList similar to HTML's classList.

### The TimingInput dictionary

The TimingInput dictionary is used as a convenience for specifying the timing properties of a TimedItem in bulk.

double delay = 0

The specified start delay.

See the description of the delay attribute on the Timing interface.

double endDelay = 0

The specified end delay.

See the description of the endDelay attribute on the Timing interface.

FillMode fill = "auto"

The fill mode as specified by one of the FillMode enumeration values.

double iterationStart = 0.0

The timed item's iteration start property.

See the description of the iterationStart attribute on the Timing interface.

unrestricted double iterations = 1.0

The timed item's iteration count property.

See the description of the iterations attribute on the Timing interface.

(unrestricted double or DOMString) duration = "auto"

The iteration duration of the timed item.

See the description of the duration attribute on the Timing interface.

double playbackRate = 1.0

The timed item's playback rate property.

See the description of the playbackRate attribute on the Timing interface.

PlaybackDirection direction = "normal"

The playback direction of the timed item.

See the description of the direction attribute on the Timing interface.

DOMString easing = "linear"

The timing function used to scale the time to produce easing effects.

See the description of the easing attribute on the Timing interface.

#### The FillMode enumeration

none
No fill.
forwards
Fill forwards.
backwards
Fill backwards.
both
Fill backwards and forwards.
auto
Fill backwards and forwards when applied to an AnimationGroup and no fill when applied to an Animation.

#### The PlaybackDirection enumeration

normal
All iterations are played as specified.
reverse
All iterations are played in the reverse direction from the way they are specified.
alternate
Even iterations are played as specified, odd iterations are played in the reverse direction from the way they are specified.
alternate-reverse
Even iterations are played in the reverse direction from the way they are specified, odd iterations are played as specified.

### The AnimationGroup interface

Animation groups are represented by the AnimationGroup interface.

Constructor ()

Creates a new AnimationGroup object using the following procedure:

1. Create a new AnimationGroup object, group.
2. Set timing input as follows,
If timing is a TimingInput object,
Let timing input refer to timing.
If timing is a double,
Let timing input be a new TimingInput object with all members set to their default values and duration set to timing.
Otherwise (timing is undefined),
Let timing input be a new TimingInput object with all members set to their default values.
3. Set group.timing to a new Timing object whose attributes are assigned the value of the member of the same name on timing input.

The above two steps are identical with the constructor for Animation and should be factored out somewhere.

4. Insert children before null.

Note that since Timing objects have the same member names as TimingInput dictionaries, it is also possible to pass the timing member of another TimedItem as the timing parameter.

Doing so will cause the Timing object to be treated as a TimingInput dictionary and thus it will effectively be cloned, not shared.

sequence<TimedItem>? children

A sequence of timed items to add as children of this group.

These children are appended in sequence using the same semantics as the AnimationGroup.append method.

optional (unrestricted double or TimingInput) timing

The timing properties or iteration duration of the new animation group.

The list of child timed items in the group.
The first child of this animation group.
The last child of this animation group.
void prepend (TimedItem... items)
1. If any of the timed items in items is an inclusive ancestor of this timed item throw a HierarchyRequestError exception and terminate these steps.
2. Insert items before the first child.
void append (TimedItem... items)
1. If any of the timed items in items is an inclusive ancestor of this timed item throw a HierarchyRequestError exception and terminate these steps.
2. Insert items before null.
AnimationGroup clone ()

Creates a deep copy of this AnimationGroup object using the following procedure.

1. Let source be this AnimationGroup object, the object to be cloned.
2. Let cloned timing be a new TimingInput object whose members are assigned the value of the attribute with the same name on source.timing.
3. Let cloned children be an empty sequence of TimedItem objects.
4. For each child in source.children, append the result of calling child.clone() to cloned children.
5. Return a new AnimationGroup object created by calling the AnimationGroup constructor with parameters AnimationGroup(cloned children, cloned timing).

## Definitions for manipulating hierarchies

The next sibling of item not included in a set of timed items, items is determined using the following steps:

1. Let context item be item.
2. While the next sibling of context item is not null perform the following steps:
1. Let context item be the next sibling of context item.
2. If context item is not in items return context item and terminate these steps.
3. Return null.

To remove an item from its parent animation group or player, perform the steps corresponding to the first matching condition from below, if any:

If item has a parent animation group,
Remove item from the parent animation group's list of child timed items.
If item is directly associated with a player,
Disassociate item from the player.

To insert a series of zero or more timed items, items, to parent's list of child timed items before reference child perform the following steps for each item in items:

1. Remove item from its parent.
2. Insert item to parent's list of child timed items before reference child.

### The TimedItemList interface

A list of timed items may be represented by a TimedItemList.

The TimedItemList interface supports indexed properties with indices in the range 0 ≤ index < length.

The only reason this interface exists is to provide a familiar experience for authors familiar with DOM interfaces where child nodes are accessed via a children member.

The number of timed items in the list.
getter TimedItem? item(unsigned long index)

Returns the timed item at index. If index is greater than or equal to length returns null.

### The AnimationSequence interface

Animation sequences are represented by the AnimationSequence interface.

Constructor (sequence<TimedItem>? children, optional (unrestricted double or TimingInput) timing)
The meaning and handling of each of the parameters in this constructor is identical to the constructor for AnimationGroup.
AnimationSequence clone ()

Creates a deep copy of this AnimationSequence object using the same procedure as defined for AnimationGroup.clone except that a new AnimationSequence object is created.

### The Animation interface

Animations are represented by the Animation interface.

Constructor ()

Creates a new Animation object using the following procedure:

1. Create a new Animation object, animation.
2. Set timing input as follows,
If timing is a TimingInput object,
Let timing input refer to timing.
If timing is a double,
Let timing input be a new TimingInput object with all members set to their default values and duration set to timing.
Otherwise (timing is undefined),
Let timing input be a new TimingInput object with all members set to their default values.
3. Set animation.timing to a new Timing object whose attributes are assigned the value of the member of the same name on timing input.
4. Set animation.effect to the result of applying the procedure for converting an effect to an IDL value to effect.

Examples of the usage of this constructor are given in .

Note that as with the constructor for AnimationGroups it is possible to pass in a Timing object here (e.g. the timing member of another TimedItem) in which case it will be cloned.

Animatable? target
The animation target or target pseudo-element. This may be null for animations that do not target a specific element.
object? effect

The animation effect used to set the effect attribute of the newly-created Animation object.

The processing of this parameter is defined normatively in . Following is a non-normative summary of this handing.

effect may be one of the following:

If this parameter is an AnimationEffect object or EffectCallback object, it will be shared with any other Animation objects referring to the same AnimationEffect or EffectCallback object. It will not be copied.

If this parameter is of type Keyframe or sequence<Keyframe>, the animation effect of the newly-created Animation will be a newly-created KeyframeEffect object initialized by using this object as the list of keyframes and with all other parameters set to their default values.

If this parameter is null, the newly-created Animation will also have a null animation effect.

optional (unrestricted double or TimingInput) timing

The timing properties or iteration duration of the new animation.

attribute (AnimationEffect or EffectCallback)? effect

The animation effect or custom effect to apply. May be null in which case the animation will produce no observable effect.

attribute Animatable? target

The element or pseudo-element being animated by this object. This may be null for animations that do not target a specific element such as an animation that produces a sound using an audio API.

Animation clone ()

Creates a copy of this Animation object using the following procedure.

1. Let source be the Animation object to clone, that is, this object.
2. Let cloned timing be a new TimingInput object whose members are assigned the value of the attribute with the same name on source.timing.
3. The AnimationEffect is cloned depending on the type of source.effect as follows,
If source.effect is an Animation object,
Let cloned effect be the result of calling source.effect.clone().
If source.effect is an EffectCallback object,
Let cloned effect be source.effect.
Otherwise,
Let cloned effect be null.
4. Return a new Animation object created by calling the Animation constructor with parameters Animation(source.target, cloned effect, cloned timing).

#### Processing the effect parameter

The effect parameter, an ECMAScript value passed to the Animation constructor or to the animate operation of the Animatable interface, may specify an EffectCallback, an AnimationEffect, a Keyframe a sequence of Keyframes, or null. However, since callback functions and dictionaries are not distinguishable in WebIDL, we define the processing of this parameter for ECMAScript here in prose.

The procedure for converting an effect to an IDL value with parameter effect is as follows:

If effect is null,
Return null.
If effect is a platform object that implements AnimationEffect,
return the IDL value that is a reference to the that platform object.
If IsCallable(effect) is true,
Return the result of applying the procedure for converting an ECMAScript value to an IDL callback function type to effect using EffectCallback as the callback function type.
Otherwise,
Return a new KeyframeEffect object constructed passing effect as the frames parameter.

Note that since the processing of this parameter is defined in prose, the above steps will take place after any coercion is applied to other parameters passed to the same operation.

#### Creating a new Animation object

The Animation constructor offers a number of approaches to creating a new Animation object. At its simplest, an Animation object that changes the ‘left’ property of elem to 100 over three seconds can be achieved as follows:

var anim = new Animation(elem, { left: '100px' }, 3000);


The second parameter, representing the animation effect, may specify multiple properties, an AnimationEffect object, or even a callback function.

// Specify multiple properties at once
var animA = new Animation(elem, { left: '100px', top: '300px' }, 3000);

// Specify multiple frames
var animB = new Animation(elem, [ { left: '100px' }, { left: '300px' } ], 3000);

// Share the animation effect of another animation
var animC = new Animation(elem, animB.effect, 3000);

// Supply a specialized animation effect
var animD =
new Animation(elem, new MotionPathEffect("M100 250C100 50 400 50 400 250"),
3000);

// Supply a custom script-based animation effect
var animE = new Animation(elem, function(time) {
// (Normally we should check for time===null, but in this case it produces
//  the correct result anyway)
document.documentElement.currentScale = 1.0 + time * 2.0;
}, 3000);


The third parameter representing the animation's timing, may simply be a number representing the iteration duration as above, or, to specify further timing properties such as the playback rate, a TimingInput object can be used as follows:

var anim =
new Animation(elem, { left: '100px' }, { duration: 3000, playbackRate: 2 });


It is also possible to omit the timing parameter altogether in which case default timing values will be used. Since the intrinsic iteration duration of an animation is zero, and the default fill when constructing an Animation is forwards, it is possible to create animations that simply set a property without any interpolation as follows,

new Animation(elem, { display: 'none' });


This is particularly useful in combination with other animations or timed items. For example, fading an element before switching ‘display’ to ‘none’ can be achieved as follows,

new AnimationSequence(
[
new Animation(elem, { opacity: '0%' }, 1000),
new Animation(elem, { display: 'none' })
]
);


Having created an Animation, it can be played using document.timeline.play(anim). For simple effects, the Element.animate shortcut is more convenient since it performs this last step automatically. For example,

elem.animate({ left: '100px' }, 3000);


### The Animatable interface

Objects that may be the target of an Animation implement the Animatable interface.

AnimationPlayer animate()

Creates a new Animation object whose animation target is the object on which the method is called, and calls the play method of the AnimationTimeline object of the document timeline of the node document [[!DOM4]] of the element passing the newly created Animation as the argument to the method.

The following code fragment:

              var anim = elem.animate({ opacity: '0' }, 2000);


is equivalent to:

              var anim = new Animation(elem, { opacity: '0' }, 2000);
elem.ownerDocument.timeline.play(anim);


Returns the AnimationPlayer object returned by the play method of the AnimationTimeline.

object? effect
The effect to apply. This value is passed to the Animation constructor as the effect parameter and has the same interpretation as defined for that constructor.
optional (double or TimingInput) timing
The timing parameters of the animation. This value is passed to the Animation constructor as the timing parameter and has the same interpretation as defined for that constructor.
sequence<Animation> getCurrentAnimations()

Returns the set of current Animation objects that have an animation effect whose animation target is this object.

The returned list of Animation objects is sorted by their associated animation effect using the procedure defined for sorting animation effects in .

Note that the definition of a current animation does not include those animations whose local time falls after the active interval but which are still in effect due to a fill mode. As a result such animations are not returned by this method.

This is because in order to return such animations, user agents would be required to maintain all animations with a forwards fill indefinitely. As a result the resources consumed by an animated document would steadily accumulate over time.

Note that when called on Element objects, the list of returned Animations will not include those animations whose target is a PseudoElement associated with the Element since PseudoElement and Element are treated as independent Animatable objects.

Feedback has been provided that suggests direct references from TimedItem objects to AnimationPlayers generate circular reference and confuse the model. Without this reference, getCurrentAnimations is not very useful, as the returned TimedItems can't be used to effect play control. In the absence of a strong use case for a reference from TimedItem to AnimationPlayer, this feature should be considered at risk.

sequence<AnimationPlayer> getAnimationPlayers()

Returns the set of AnimationPlayer objects whose source content is current and contains at least one animation whose animation target is this object.

If this object is the animation target of two or more animations which are associated with the same player, the corresponding AnimationPlayer object will still only appear in the returned list once.

The returned list is sorted in increasing order by player sequence number.

### The AnimationEffect interface

Animation effects are represented by the AnimationEffect interface. AnimationEffect is an abstract interface of which several concrete subinterfaces are provided.

attribute AccumulateOperation accumulate

The accumulation operation property of this animation effect as specified by one of the AccumulateOperation constants.

attribute CompositeOperation composite

The composition operation used to composite this animation effect with the animation stack, as specified by one of the CompositeOperation enumeration values.

AnimationEffect clone ()

Creates and returns a new object of the same type as this object's most-derived interface such that it will produce the same output as this object.

We either need a more rigorous definition here or (probably better) a sets of steps on a per-subclass basis.

In future, we may expose any sample (double? timeFraction, double currentIteration, Animatable? target, any underlyingValue) so that the animation effects can be driven apart from the timing model.

### The AccumulateOperation enumeration

The possible values of an animation effect's accumulation behavior are represented by the AccumulateOperation enumeration.

sum
Corresponds to the sum accumulation operation value such that subsequent iterations of an animation build on the final value of the previous iteration.
none
Corresponds to the none accumulation operation value such that the intermediate animation value produced is independent of the current iteration.

### The CompositeOperation enumeration

The possible values of an animation effect's composition behavior are represented by the CompositeOperation enumeration.

replace
Corresponds to the replace composition operation value such that the animation effect overrides the underlying value it is combined with.
Corresponds to the add composition operation value such that the animation effect is added to the underlying value with which it is combined.
accumulate
Corresponds to the accumulate composition operation value such that the animation effect is accumulated on to the underlying value.

### The KeyframeEffect interface

Keyframe animation effects are represented by the KeyframeEffect interface.

Constructor ()

Creates a new KeyframeEffect object for the given set of keyframes.

object frames
A Keyframe object or sequence of Keyframe objects used for calculating animation values for this animation effect. The constraints on this parameter and its processing are identical to those for setFrames.
optional KeyframeEffectOptions options
A KeyframeEffectOptions dictionary defining other aspects of the animation effect's behavior. If this parameter is not provided, the default values of the dictionary are used.
attribute DOMString spacing

The spacing mode to use for this animation effect.

Recognized values are defined by the following grammar:

distribute | paced({ident}) | paced

{ident} here is an identifier as defined by CSS3 Values [[!CSS3-VALUES]].

The meaning of each value is as follows:

distribute
Use the distribute keyframe spacing mode.
paced({ident})

Use the paced keyframe spacing mode with the property name indicated by {ident} as the paced property.

For example, paced(transform) would indicate that the keyframes should be spaced such that changes to the transform property occur at a constant rate.

paced

Use the paced keyframe spacing mode.

The paced property to use is the first property specified in the first keyframe in the list of keyframes associated with this animation effect when sorting the CSS property names in ascending order by Unicode codepoint.

As a result, changes to the keyframes may cause the paced property to change.

Note that this behavior is generally not useful for keyframes specifying more than one property. It is provided for consistency with MotionPathEffect and as a convenience for keyframe animation effects that specify only one property.

All other values are treated as "distribute" for the purpose of animation model calculations.

sequence<ComputedKeyframe> getFrames()

Returns the keyframes that make up this effect as a sequence of ComputedKeyframe objects.

The value returned differs from the frames parameter passed into setFrames or the constructor for this interface in the following ways:

• The normalization defined in is applied to frames which may result in some frames being removed or re-ordered and some properties being removed. This normalization will also cause a single Keyframe object to be replaced with a sequence.
• The result of computing the keyframe offset of each keyframe as defined in is stored in the computedOffset member of each frame.
void setFrames(object frames)

A Keyframe object or sequence of Keyframe objects used to replace the set of keyframes that make up this effect.

The processing of the frames parameter is defined in . Subsequently, the resulting sequence of Keyframe objects is normalized using the procedure in before storing.

## Processing a sequence of Keyframe objects or a single item

WebIDL does not currently make a dictionary and a sequence distinguishable but it was felt that allowing both was important for useability of the animate operation on Animatable. Therefore, we define the processing for handling a parameter that may be either a single Keyframe dictionary object, or a sequence of such objects.

The procedure for converting an ECMAScript value into an IDL keyframe or sequence of keyframes with parameter keyframeOrKeyframeList is as follows:

If, using the canonical definition of Array.isArray [[!ECMA-262]], Array.isArray(keyframeOrKeyframeList) is true,
Return the result of following the steps for converting an ECMAScript value into an IDL sequence using the procedure for converting an ECMAScript value to an IDL Keyframe object as the procedure for converting E to an IDL value of type T.
Otherwise,
Return the result of applying the procedure for converting an ECMAScript value to an IDL Keyframe object to keyframeOrKeyframeList.

Should this be defined in terms of IsIterable instead?

## The KeyframeEffectOptions dictionary

Additional parameters may be passed to the KeyframeEffect constructor by providing a KeyframeEffectOptions object.

AccumulateOperation accumulate = "none"
The accumulation operation used to define the way animation values build from iteration to iteration.
CompositeOperation composite = "replace"
The composition operation used to composite this animation with the animation stack, as specified by one of the CompositeOperation enumeration values. This is used for all keyframes that do not specify a composition operation.
DOMString spacing = "distribute"

The spacing mode to apply to this animation effect's keyframes.

See the description of the spacing attribute of the KeyframeEffect interface for the recognized values and their meaning are described

Unrecognized values are set on the created KeyframeEffect object, but are treated as "distribute" for the purpose of animation model calculations.

#### Normalizing a sequence of keyframes

For each call to setFrames or the KeyframeEffect constructor, the following normalization is performed on the passed in frames parameter before storing its value.

Note that the processing of the ECMAScript value into a suitable IDL value defined in is performed before this operation is initiated.

1. If frames is a single Keyframe object, replaces frames with a new sequence with a single item that is the previous value of frames.
2. If frames is not loosely sorted by offset, then,
If each Keyframe has a non-null offset,
Sort frames in ascending order by offset.
Otherwise,
Throw a DOMException of type InvalidModificationError.
3. If there exist any Keyframe objects in frames whose offset member is non-null and less than zero, remove all keyframes objects from the start of frames up to and including the keyframe with the largest non-null offset that is still less than zero.
4. Likewise, if there exist any Keyframe objects in frames whose offset member is non-null and greater than one, remove all keyframes from the keyframe with the smallest non-null offset that is still greater than one until the end of frames.
5. Remove all property values in frames that are invalid or not supported by the implementation.

Need to define what invalid means here.

### The Keyframe dictionary

Individual keyframes are represented by a special kind of Keyframe dictionary type whose members map to the properties to be animated. At the time of writing, this kind of open-ended dictionary cannot be represented using WebIDL and hence special ECMAScript-specific handling for this type is defined in . No handling is defined for other languages.

// ... property-value pairs ...
double? offset = null

The keyframe offset of the keyframe specified as a number between 0.0 and 1.0 inclusive or null.

Keyframes with offsets outside the range [0.0, 1.0] are ignored when calculating animation values as defined in .

A null value indicates that the keyframe should be positioned using the keyframe animation effect's keyframe spacing mode.

DOMString easing = "linear"

The timing function used to transform the progress of time from this keyframe until the next keyframe in the series.

The syntax and error-handling associated with parsing this string is identical to that defined for the easing attribute of the Timing interface.

CompositeOperation? composite = null

The composition operation used to combine the values specified in this keyframe with the underlying value.

If null, the composition operation specified on the AnimationEffect will be used.

#### Processing a Keyframe object

Since accessing the properties of an ECMAScript user object can have side effects, the manner in which these properties is accessed is important. In light of this consideration the procedure for converting an ECMAScript object into an IDL Keyframe object has the following properties:

• Properties are read in a well-defined order.
• Properties corresponding to unsupported target properties or attributes are not read.

The procedure for converting an ECMAScript value to an IDL Keyframe object with parameter keyframe input is as follows:

1. Let keyframe result be a Keyframe object with the offset, easing and composite attributes set to the default dictionary values.
2. Create a list, supported properties, of property names and attribute names that can be animated by the implementation.
3. Convert each property name in supported properties to the equivalent IDL attribute by applying the CSS property to IDL attribute algorithm [[!CSSOM]].
4. If the user agent supports animation of the float CSS property, replace 'float' in supported properties with 'cssFloat'.
5. Let animation properties be an empty sequence.
6. Use the internal [‌[Enumerate]] operation on keyframe input to iterate over its properties. For each property perform the step corresponding to the first matching condition from below, if any.
If property is a case-sensitive match for the string 'offset',
Set the offset member of keyframe result to the result of applying the procedure for converting an ECMAScript value into an IDL double [[!WEBIDL]] to the result of calling the [‌[Get]] internal method on keyframe input with property name 'offset'.
If property is a case-sensitive match for the string 'easing',

Set the easing member of keyframe result to the result of applying the procedure for converting an ECMAScript value to an IDL DOMString value [[!WEBIDL]] with the [TreatNullAs=EmptyString] annotation in effect, to the result of calling the [‌[Get]] internal method of keyframe input with property name 'easing'.

If the resulting string does not conform to the grammar defined for the easing attribute of the Timing interface or is not supported by the implementation, then set the easing of keyframe result to the string “linear”.

If property is a case-sensitive match for the string 'composite',
Set the composite member of keyframe result to the result applying the procedure for converting an ECMAScript value to an IDL enumeration type [[!WEBIDL]] with CompositeOperation as the enumeration type, to the result of calling the [‌[Get]] internal method on keyframe input with property name 'composite'.
Otherwise, if property also exists in supported properties based on a case-sensitive comparison,
append property to animation properties.
7. For user agents that support both a prefixed and an unprefixed version of some CSS properties, remove all prefixed properties from animation properties where the corresponding unprefixed version is also present in animation properties.

I'd like to remove this step. Prefixes are history.

8. Sort animation properties lexicographically by the Unicode codepoints that define each element.
9. Iterate over animation properties from beginning to end and for each name in animation properties add a new member pair to keyframe result as follows:
• member name: the result of applying the the IDL attribute to CSS property algorithm [[!CSSOM]] to name unless name is a case-sensitive match for the string 'cssFloat' in which case use the string 'float'.
• member value: the result of calling ToString on the value returned from the [‌[Get]] method of keyframe input with property name, name. If [‌[Get]] returns null or undefined, let the member value be an empty string.
10. Return keyframe result.

The above algorithm gives special meaning to the property names 'offset', 'computedOffset', 'easing', and 'composite'. If a CSS property called 'offset' or 'composite' is ever introduced it will clash with the meaning here.

We have a few options:

• Add special handling at that time to allow addressing the property of the same name, e.g. cssOffset.
• Rename these keywords now to reduce risk of a later clash, e.g. 'keyframeOffset'.

### The ComputedKeyframe dictionary

Keyframes returned by KeyframeEffect.getFrames are represented using ComputedKeyframe dictionary objects.

double computedOffset
The keyframe offset calculated for this keyframe as a result of applying the spacing procedure defined in .

### The MotionPathEffect interface

Motion path animation effects are represented by the MotionPathEffect interface.

Constructor ()

Creates a new MotionPathEffect object with the specified parameters.

(DOMString or SVGPathSegList) path

The motion path which defines the course the animation target follows.

A string may be provided specifying the path using the syntax for SVG path data [[!SVG2]].

If a string is provided, it is converted into an SVGPathSegList using the procedure defined for parsing path data in [[!SVG2]]. Any errors encountered in the path data cause parsing to cease and the path data processed up to that point to be used.

The resulting SVGPathSegList is assigned to the path attribute of the generated object without copying.

optional MotionPathEffectOptions options
A MotionPathEffectOptions dictionary defining other aspects of the animation effect's behavior. If this parameter is not provided, the default values of the dictionary are used.
attribute SVGPathSegList segments
The list of segments that make up the motion path.
attribute AutoRotationMode autoRotate
The automatic rotation flag of the motion path animation effect.
attribute double angle
The rotation angle of the motion path animation effect.
attribute DOMString spacing

The motion path spacing mode to use for this animation effect.

Recognized values are defined by the following grammar:

distribute | paced

The meaning of each value is as follows:

distribute
Use the distribute spacing mode.
paced
Use the paced spacing mode.

All other values are treated as "paced" for the purpose of animation model calculations.

## The MotionPathEffectOptions dictionary

Additional parameters may be passed to the MotionPathEffect constructor by providing a MotionPathEffectOptions object.

AutoRotationMode autoRotate = "none"
The automatic rotation flag setting for the generated effect.
double angle = 0
The rotation angle for the generated effect.
AccumulateOperation accumulate = "none"
The accumulation operation used to define the way animation values build from iteration to iteration.
CompositeOperation composite = "replace"
The composition operation used to composite this animation effect with the animation stack, as specified by one of the CompositeOperation enumeration values.
DOMString spacing = "paced"

The spacing mode to apply to this motion path animation effect.

See the description of the spacing attribute of the MotionPathEffect interface for the recognized values and their meaning are described

Unrecognized values are set on the created MotionPathEffect object, but are treated as "paced" for the purpose of animation model calculations.

#### The AutoRotationMode enumeration

The values of the automatic rotation flag of a motion path animation effect are represented by the AutoRotationMode enumeration.

auto-rotate
Corresponds to setting the automatic rotation flag.
none
Corresponds to clearing the automatic rotation flag.

### The EffectCallback callback function

Custom effects can be defined in script by providing an EffectCallback callback function.

An EffectCallback is called each time an Animation with which it is associated is sampled.

double? timeFraction
The time fraction for which to produce an effect. When this is null, the function SHOULD remove the effect.
Animation animation
The Animation object that is being sampled.
double? previousTimeFraction

The value of timeFraction that was passed to this EffectCallback when it was previously called in the context of sampling the same Animation that generated the current call.

If this EffectCallback has not previously been called within the context of sampling the same Animation as with the current call, or if the time fraction was null on the previous call, this parameter will be null.

### The AnimationPlayerEvent interface

Player events are represented in the API by the AnimationPlayerEvent interface.

Constructor ()
Constructs a new AnimationPlayerEvent object as described in Constructing events in [[!DOM4]].
DOMString type
The type of player event corresponding to one of the types defined in .
optional AnimationPlayerEventInit eventInit
The parameters of the new AnimationPlayerEvent.
attribute double? currentTime
The event current time.
attribute double? timelineTime
The event timeline time.

The AnimationPlayerEventInit dictionary type is used to specify the parameters when constructing a AnimationPlayerEvent object.

double? currentTime = null
double? timelineTime = null

### Extensions to the Document interface

The following extensions are made to the Document interface defined in [[!DOM4]].

The AnimationTimeline object representing the document timeline.

### Extensions to the Element interface

Since DOM Elements may be the target of an animation, the Element interface [[!DOM4]] is extended as follows:

This allows the following kind of usage.

            elem.animate({ color: 'red' }, 2000);


### Extensions to the PseudoElement interface

Since animations may also target pseudo-elements, the PseudoElement interface [[!CSSOM]] is also defined to be animatable.

This interface is marked at-risk in the 5 December 2013 WD of CSSOM. If it is removed, we will need to provide an equivalent definition here.

## Script execution and live updates to the model

The interaction between script execution and the state and effects of the Web Animations model is as follows:

• Changes made to the Web Animations model via the programming interface are reflected immediately in the values returned by the interfaces defined in this specification.

Similarly, methods that operate on the current state of the model such as pausing or reversing are applied to a fully-updated timing model, that is, after all previous modifications have been incorporated.

For example, if the AnimationPlayer associated with an Animation is seeked via the programming interface, the value returned when querying the animation's startTime will reflect updated state of the model immediately.

                // Initially player.src.localTime is 3000
player.currentTime += 2000;


The same concept applies to more complex modifications of the Web Animations model such as adding and removing children from an AnimationGroup.

• Querying the computed style of a property affected by animation, or the value of an attribute affected by animation, returns the value based the current state of the model, that is, after incorporating any modifications made using the programming interface.

For example, if the used style of an element is queried immediately after applying a new Animation to that element, the result of the new animation will be incorporated in the value returned.

                // Set opacity to 0 immediately
elem.animate({ opacity: '0' });


The means of querying the animated value of an attribute depends on the interface defined for the attribute. SVG 1.1 [[!SVG11]] defines an additional interface for querying animated values.

                // Set width to 0 immediately
rect.animate({ width: '100px' });

• Changes made to the model using the programming interface do not cause any EffectCallback functions to be called.

For example, in the following code, the callback function will not be called until after the script block has completed during regular sampling.

                var timesCalled = 0;
elem.animate(function() {
timesCalled++;
}, 10000);

• Changes to specified style, specified attribute values, and the state of the Web Animations model made within the same execution block must be synchronized when rendering such that the whole set of changes is rendered together.

For example, a user agent must not render only the changes to specified style made in a script execution block whilst ignoring changes to animations. This guarantees that the following usage will never produce a situation where only the change to specified style is rendered without the animation.

                // Fade the opacity with fallback for browsers that don't
// support Element.animate
elem.style.opacity = '0';
elem.animate([ { opacity: '1' }, { opacity: '0' } ], 500);


Note that a user agent may render a frame with none of the changes made in a script execution block. This might happen, for example, if rendering occurs in a separate process that is scheduled to run shortly after a script execution block completes but before changes made via script can be communicated to the process.

• The value returned by the currentTime attribute of a document timeline will not change within a script block.

For example, querying the currentTime twice within a long block of code that is executed in the same script block will return the same value as shown in the following example.

                var a = document.timeline.currentTime;
// ... many lines of code ...
var b = document.timeline.currentTime;
alert(b - a); // Displays 0


## Integration with Media Fragments

The Media Fragments specification [[!MEDIA-FRAGMENTS]] defines a means for addressing a temporal range of a media resource. The application of media fragments depends on the MIME type of the resource on which they are specified. For resources with the SVG MIME type [[!SVG11]], the application of temporal parameters is defined in the Animation elements specification.

Note that media fragments are defined to operate on resources based on their MIME type. As a result, temporal addressing may not be supported in all situations where Web Animations content is used.

## Interaction with page display

HTML permits user agents to store user-agent defined state along with a session history entry so that as a user navigates between pages, the previous state of the page can be restored including state such as scroll position [[HTML5]].

User agents that pause and resume media elements when the referencing document is unloaded and traversed, are encouraged to apply consistent handling to documents containing Web Animations content. If provided, this behavior SHOULD be achieved by adjusting the time values of any timelines bound to the global clock.

## Implementation requirements

### Precision of time values

The internal representation of time values is implementation dependant however, it is RECOMMENDED that user agents be able to represent input time values with microsecond precision so that 0.000001 is distinguishable from 0.0.

### Conformance criteria

This specification defines an abstract model for animation and, as such, for user agents that do not support scripting, there are no conformance criteria since there is no testable surface area.

User agents that do not support scripting, however, may implement additional technologies defined in terms of this specification in which case the definitions provided in this specification will form part of the conformance criteria of the additional technology.

A conforming scripted Web Animations user agent is a user agent that implements the API defined in including dispatching events as defined in .

## Acknowledgements

Thank you to Michiel “Pomax” Kamermans for help with the equations for a proposed smooth timing function although this feature has been deferred to a subsequent specification.

Our deep gratitude goes out to Southern Star Animation for their kind generosity and patience in introducing the editors to the processes and techniques used producing broadcast animations.

## Changes since last publication

The following changes have been made since the 25 June 2013 Working Draft.

• Changed the basic unit of time from seconds to milliseconds.
• Altered the zero time for the document timeline to correspond to the navigationStart moment defined by [[!NAVIGATION-TIMING]].
• Altered the definition of effective current time.
• Removed the ‘time drift’ property of players and redefined play control algorithms in terms of an adjusted start time.
• Introduced limiting behavior to players so that the current time behaves more like a DVD or cassette player.
• Introduced an end delay property to timed items.
• Reworked the description of timed item states to include phases as well. Renamed the ‘active’ state to the in play state.
• Changed the behavior of fill modes so that children that are clipped part-way through their active interval by a parent animation group only fill if they have the corresponding fill mode set.
• Fixed a bug in the calculation of the current iteration for zero-length iteration durations ().
• Added extra wording so that a timed item with a step timing function whose transition point coincides with either end of the active interval produces the expected value when filling.
• Fixed a bug in the calculation of the transformed time so that children of groups with infinite duration will play.
• Fixed a bug in the calculation of the time fraction for zero-length iteration durations ().
• Clarified behavior in a number of cases where a value of infinity may be multiplied with zero.
• Renamed timing groups, animation groups. Parallel timing groups are now simply animation groups, and sequence timing groups are now animation sequences.
• Rewrote and re-organized most of the animation model section (see ) to provide greater internal consistency. CSS properties are now animatable by default and procedures for interpolation, addition, and distance computation are now defined for all cases (see ).
• Renamed the target element of an animation to the animation target.
• Made the custom animation priority specific to a player and renamed it to the custom player priority.
• Made the composition operation a property of all animation effects.
• Added the accumulate composition operation.
• Replaced paced timing functions with spacing behavior that can either evenly distribute values or space them to maintain an even rate of change.
• Added spacing modes, spacing points, and point offsets to motion path animation effects in order to support all the features of SVG's animateMotion element.
• Removed custom effect priorities.
• Renamed the Timeline interface to AnimationTimeline.
• Renamed getCurrentPlayers on the AnimationTimeline interface to getAnimationPlayers.
• Renamed Player interface to AnimationPlayer.
• Added onfinish to the AnimationPlayer interface as the event handler for the new finish player event and made the AnimationPlayer interface inherit from EventTarget.
• Added the following members to the AnimationPlayer interface:
• finished
• cancel()
• finish()
• play()
• pause()
• reverse()
• Made the paused member of the AnimationPlayer interface readonly.
• Removed the event handlers from TimedItem since timing events have been replaced with player events. Similarly, made the TimedItem interface no longer inherit from EventTarget.
• Marked TimedItem.player as at risk.
• Renamed the specified attribute on TimedItem to timing.
• Renamed the following members of the Timing interface and TimingInput dictionary:
• iterationDurationduration
• startDelaydelay
• fillModefill
• iterationCountiterations
• timingFunctioneasing
• Removed the activeDuration member of the TimingInput dictionary and Timing interface and introduced endDelay to both.
• Introduced an auto value for FillMode and made it the default value for fill on TimingInput.
• Added timing function syntax directly to this specification rather than referring to [[CSS3-TRANSITIONS]].
• Removed the abstract TimingGroup interface and renamed ParGroup to AnimationGroup.
• Renamed SeqGroup to AnimationSequence and made it inherit from AnimationGroup.
• Changed the type of the effect argument to the Animation constructor and the Animatable.animate method to object? and defined its processing.
• Removed null as a possible value for the timing parameter of the AnimationGroup, AnimationSequence and Animation constructors and the Animatable.animate method.
• Made the target member of the Animation interface no longer readonly.
• Removed the AnimationTarget typedef and introduced the Animatable interface in its place.
• Made Animatable.animate return an AnimationPlayer instead of an Animation.
• Marked Animatable.getCurrentAnimations as at risk.
• Moved the composite member of KeyframeEffect and MotionPathEffect to the base class, AnimationEffect.
• Renamed KeyframeAnimationEffect to KeyframeEffect.
• Changed the constructor for KeyframeEffect to take a KeyframeEffectOptions dictionary object.
• Added a spacing member to both KeyframeEffect and KeyframeEffectOptions to specify spacing behavior.
• Made getFrames on KeyframeEffect return the computed keyframe offset as computedOffset and apply the normalization of keyframes defined in .
• Introduced the ComputedKeyframe dictionary for representing the return values from KeyframeEffect.getFrames.
• Removed the OneOrMoreKeyframes typedef since it is no longer a valid WebIDL union. Replaced useage of OneOrMoreKeyframes with object and defined its processing.
• Made the normalization of keyframes no longer fill in the offset of a keyframe. This is now incorporated in which is now a core part of the model.
• Defined the procedure used for iterating of the properties of a passed in keyframe object as using [‌[Enumerate]].
• Made the normalization of keyframes sort keyframes if all keyframe offset are specified or otherwise throw an exception if the frames are not loosely sorted by offset and not all offsets are specified since the desired result in this case is ambiguous.
• Added the easing member to the Keyframe dictionary.
• Renamed path animation effects to motion path animation effects and likewise PathAnimationEffect to MotionPathEffect.
• Changed the constructor for MotionPathEffect to take a MotionPathEffectOptions dictionary object.
• Added the spacing member to the MotionPathEffect interface.
• Replaced the CustomEffect callback interface with the EffectCallback callback function and replaced the currentIteration and target parameters with the Animation object that is being sampled.
• Renamed getCurrentPlayers on the Element interface to getAnimationPlayers.
• Removed the PseudoElementReference interface to use the PseudoElement interface from CSSOM instead.
• Revised so that computed style reflects the current state of the model.

The changelog provides a more detailed history.