This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The EffectTiming
dictionary's easing
property in the Web Animations API specifies the timing function used to scale the time to produce easing effects, where easing is the rate of the animation's change over time.
Element.animate()
, KeyframeEffectReadOnly()
, and KeyframeEffect()
all accept an object of timing properties including easing
. The value of easing corresponds directly to AnimationEffectTimingReadOnly.easing
in timing
objects returned by AnimationEffectReadOnly
, KeyframeEffectReadOnly
, and KeyframeEffect
.
var timingProperties = { easing: <single-transition-timing-function> } timingProperties.easing = <single-transition-timing-function>
A string defining the timing function to use for easing transitions during the animation process. Accepts several pre-defined DOMString
values, a steps()
timing function like steps(5, end)
, or a custom cubic-bezier
value like cubic-bezier(0.42, 0, 0.58, 1)
. Defaults to linear
. Available values include:
linear
cubic-bezier(<number>, <number>, <number>, <number>)
ease
cubic-bezier(0.25, 0.1, 0.25, 1)
.ease-in
cubic-bezier(0.42, 0, 1, 1)
.ease-out
cubic-bezier(0, 0, 0.58, 1)
.ease-in-out
cubic-bezier(0.42, 0, 0.58, 1)
.frames(<integer>)
steps()
and frames()
.steps(<integer>[, [ start | end ] ]?)
step-start
steps(1, start)
step-end
steps(1, end)
.In the Red Queen's Race example, we animate Alice and the Red Queen by passing an easing of steps(7, end)
to animate()
:
// Define the key frames var spriteFrames = [ { transform: 'translateY(0)' }, { transform: 'translateY(-100%)' } ]; // Get the element that represents Alice and the Red Queen var redQueen_alice_sprite = document.getElementById('red-queen_and_alice_sprite'); // Animate Alice and the Red Queen using steps() var redQueen_alice = redQueen_alice_sprite.animate( spriteFrames, { easing: 'steps(7, end)', direction: "reverse", duration: 600, playbackRate: 1, iterations: Infinity });
Specification | Status | Comment |
---|---|---|
Web Animations The definition of 'easing' in that specification. | Working Draft | Editor's draft. |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | Yes | ? | 63 | No | Yes | No |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | ? | ? | ? | 63 | No | No | ? |
Element.animate()
, KeyframeEffectReadOnly()
, and KeyframeEffect()
all accept an object of timing properties including this one.AnimationEffectTimingReadOnly
(which is the timing
object for AnimationEffectReadOnly
, KeyframeEffectReadOnly
, and KeyframeEffect
).animation-timing-function
and transition-timing-function
.
© 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/EffectTiming/easing