W3cubDocs

/DOM

AnimationEffectTimingReadOnly.duration

This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The duration property of AnimationEffectTimingReadOnly represents the duration in milliseconds to complete a single iteration of the animation.

Note: In AnimationEffectTiming, a mutable subclass of AnimationEffectTimingReadOnly used withKeyframeEffects, the property acts as both a getter and a setter.

Syntax

// Getting the duration of each iteration
var animationLoopDuration = animation.effect.timing.duration;

// Setting the duration of each iteration
animation.effect.timing.duration = 5000;

Value

The number of milliseconds long a single beginning-to-end iteration of the animation should take. The default is "auto". This value must not be negative; otherwise, it can have any value (including positive infinity).

Currently, a value of "auto" is the same as specifying 0.0. This is a forwards-compatiblity measure since in the future, "auto" will be expanded to take into account the duration of any child effects. Consider using "auto" rather than 0 if that makes sense.

Examples

In the Red Queen's Race example, we set the background's animation to begin halfway through its first loop:

var sceneryTimingBackground = {
  duration: 36000,
  iterations: Infinity
};

var sceneryTimingForeground = {
  duration: 12000,
  iterations: Infinity
};

var background1 = document.getElementById('background1');

// Animating the background
var background1Movement = background1.animate( sceneryFrames, sceneryTimingBackground );

// Setting the background animation's start position based on its duration
background1Movement.currentTime = background1Movement.effect.timing.duration / 2;

Specifications

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support (Yes) 48 (48)[1] No support (Yes) No support
Feature Android Android Webview Chrome for Android Firefox Mobile (Gecko) Firefox OS IE Mobile Opera Mobile Safari Mobile
Basic support ? ? ?[1] ? ? No support No support No support

[1] The Web Animations API is only enabled by default in Firefox Developer Edition and Nightly builds. You can enable it in beta and release builds by setting the preference dom.animations-api.core.enabled to true, and can disable it in any Firefox version by setting this preference to false.

See also

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/AnimationEffectTimingReadOnly/duration