Skip to main content

Animation

The Animation interface of the Web Animations API represents a single animation player and provides playback controls and a timeline for an animation node or source.

MDN Reference

Extends​

Methods​

addEventListener()​

Call Signature​

addEventListener<K>(
type,
listener,
options?
): void;

The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.

MDN Reference

Type Parameters​
Type Parameter
K extends keyof AnimationEventMap
Parameters​
ParameterType
typeK
listener(this, ev) => any
options?boolean | AddEventListenerOptions
Returns​

void

Overrides​

EventTarget.addEventListener

Call Signature​

addEventListener(
type,
listener,
options?
): void;

The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.

MDN Reference

Parameters​
ParameterType
typestring
listenerEventListenerOrEventListenerObject
options?boolean | AddEventListenerOptions
Returns​

void

Overrides​
EventTarget.addEventListener

cancel()​

cancel(): void;

The Web Animations API's cancel() method of the Animation interface clears all KeyframeEffects caused by this animation and aborts its playback.

MDN Reference

Returns​

void


commitStyles()​

commitStyles(): void;

The commitStyles() method of the Web Animations API's Animation interface writes the computed values of the animation's current styles into its target element's style attribute.

MDN Reference

Returns​

void


dispatchEvent()​

dispatchEvent(event): boolean;

The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. The normal event processing rules (including the capturing and optional bubbling phase) also apply to events dispatched manually with dispatchEvent().

MDN Reference

Parameters​

ParameterType
eventEvent

Returns​

boolean

Inherited from​

EventTarget.dispatchEvent


finish()​

finish(): void;

The finish() method of the Web Animations API's Animation Interface sets the current playback time to the end of the animation corresponding to the current playback direction.

MDN Reference

Returns​

void


pause()​

pause(): void;

The pause() method of the Web Animations API's Animation interface suspends playback of the animation.

MDN Reference

Returns​

void


persist()​

persist(): void;

The persist() method of the Web Animations API's Animation interface explicitly persists an animation, preventing it from being automatically removed when it is replaced by another animation.

MDN Reference

Returns​

void


play()​

play(): void;

The play() method of the Web Animations API's Animation Interface starts or resumes playing of an animation. If the animation is finished, calling play() restarts the animation, playing it from the beginning.

MDN Reference

Returns​

void


removeEventListener()​

Call Signature​

removeEventListener<K>(
type,
listener,
options?
): void;

The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target. The event listener to be removed is identified using a combination of the event type, the event listener function itself, and various optional options that may affect the matching process; see Matching event listeners for removal.

MDN Reference

Type Parameters​
Type Parameter
K extends keyof AnimationEventMap
Parameters​
ParameterType
typeK
listener(this, ev) => any
options?boolean | EventListenerOptions
Returns​

void

Overrides​

EventTarget.removeEventListener

Call Signature​

removeEventListener(
type,
listener,
options?
): void;

The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target. The event listener to be removed is identified using a combination of the event type, the event listener function itself, and various optional options that may affect the matching process; see Matching event listeners for removal.

MDN Reference

Parameters​
ParameterType
typestring
listenerEventListenerOrEventListenerObject
options?boolean | EventListenerOptions
Returns​

void

Overrides​
EventTarget.removeEventListener

reverse()​

reverse(): void;

The Animation.reverse() method of the Animation Interface reverses the playback direction, meaning the animation ends at its beginning. If called on an unplayed animation, the whole animation is played backwards. If called on a paused animation, the animation will continue in reverse.

MDN Reference

Returns​

void


updatePlaybackRate()​

updatePlaybackRate(playbackRate): void;

The updatePlaybackRate() method of the Web Animations API's Animation Interface sets the speed of an animation after first synchronizing its playback position.

MDN Reference

Parameters​

ParameterType
playbackRatenumber

Returns​

void

Properties​

currentTime​

currentTime: CSSNumberish | null;

The Animation.currentTime property of the Web Animations API returns and sets the current time value of the animation in milliseconds, whether running or paused.

MDN Reference


effect​

effect: AnimationEffect | null;

The Animation.effect property of the Web Animations API gets and sets the target effect of an animation. The target effect may be either an effect object of a type based on AnimationEffect, such as KeyframeEffect, or null.

MDN Reference


finished​

readonly finished: Promise<Animation>;

The Animation.finished read-only property of the Web Animations API returns a Promise which resolves once the animation has finished playing.

MDN Reference


id​

id: string;

The Animation.id property of the Web Animations API returns or sets a string used to identify the animation.

MDN Reference


oncancel​

oncancel: ((this, ev) => any) | null;

MDN Reference


onfinish​

onfinish: ((this, ev) => any) | null;

MDN Reference


onremove​

onremove: ((this, ev) => any) | null;

MDN Reference


overallProgress​

readonly overallProgress: number | null;

The overallProgress read-only property of the Animation interface returns a number between 0 and 1 indicating the animation's overall progress towards its finished state. This is the overall progress across all of the animation's iterations, not each individual iteration.

MDN Reference


pending​

readonly pending: boolean;

The read-only Animation.pending property of the Web Animations API indicates whether the animation is currently waiting for an asynchronous operation such as initiating playback or pausing a running animation.

MDN Reference


playbackRate​

playbackRate: number;

The Animation.playbackRate property of the Web Animations API returns or sets the playback rate of the animation.

MDN Reference


playState​

readonly playState: AnimationPlayState;

The read-only Animation.playState property of the Web Animations API returns an enumerated value describing the playback state of an animation.

MDN Reference


ready​

readonly ready: Promise<Animation>;

The read-only Animation.ready property of the Web Animations API returns a Promise which resolves when the animation is ready to play. A new promise is created every time the animation enters the "pending" play state as well as when the animation is canceled, since in both of those scenarios, the animation is ready to be started again.

MDN Reference


replaceState​

readonly replaceState: AnimationReplaceState;

The read-only Animation.replaceState property of the Web Animations API indicates whether the animation has been removed by the browser automatically after being replaced by another animation.

MDN Reference


startTime​

startTime: CSSNumberish | null;

The Animation.startTime property of the Animation interface is a double-precision floating-point value which indicates the scheduled time when an animation's playback should begin.

MDN Reference


timeline​

timeline: AnimationTimeline | null;

The Animation.timeline property of the Animation interface returns or sets the timeline associated with this animation. A timeline is a source of time values for synchronization purposes, and is an AnimationTimeline-based object. By default, the animation's timeline and the Document's timeline are the same.

MDN Reference