This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the specification changes.
The KeyframeEffect()
constructor of the Web Animations API returns a new
object instance.KeyframeEffect
Syntax
var keyframes = new keyframeEffect(element, keyframeSet, keyframeOptions);
Parameters
- element
- The DOM element to be animated.
- keyframeSet
- An array of keyframe objects — these are property value pairs (as seen in the Examples section.)
- keyframeOptions
- Either an integer representing the animation's duration (in milliseconds), or an object containing optional animation timing options, which can include those detailed in the animation timing options reference, and can also include the Additional keyframeOptions listed below.
-
Additional keyframeOptions
composite Optional
- Determines how values are combined between this animation and other, separate animations that do not specify their own composite operation. The available options are as follows (defaults to
replace
):add
dictates an additive effect, where each successive iteration builds on the last. For instance withtransform
, atranslateX(-200px)
would not override an earlierrotate(20deg)
value but instead result intranslateX(-200px) rotate(20deg)
.accumulate
is similar but a little smarter:blur(2)
andblur(5)
would combine to becomeblur(7)
, notblur(2) blur(5)
.replace
overwrites the previous value with the new one.
iterationComposite Optional
- Determines how values build from iteration to iteration in the current animation. This can be set to
accumulate
orreplace
(see above), and defaults toreplace
. spacing Optional
- Determines how keyframes without temporal offsets should be distributed during the animation's duration. It cna take the following values (defaults to
distribute
):distribute
positions keyframes so that the difference between subsequent keyframe offsets are equal, that is to say, without any offsets, it will equally distribute the keyframes across play time.paced
positions keyframes so that the distance between subsequent values of a specified paced property are equal, that is to say, keyframes are spaced further apart the greater the difference in their property values.
Examples
In the Follow the White Rabbit example, the KeyframeEffect
constructor is used to create a set of keyframes that dictate how the White Rabbit should animate down the hole:
var rabbitDownKeyframes = new KeyframeEffect( whiteRabbit, // element to animate [ { transform: 'translateY(0%)' }, // keyframe { transform: 'translateY(100%)' } // keyframe ], { duration: 3000, fill: 'forwards' } // keyframe options );
Specifications
Specification | Status | Comment |
---|---|---|
Web Animations The definition of 'keyframeEffect()' in that specification. |
Working Draft | Editor's draft. |
Browser compatibility
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | ? | ? | ? | ? | ? |
Feature | Android | Android Webview | Firefox Mobile (Gecko) | Firefox OS | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|---|
Basic support | ? | ? | ? | ? | ? | ? | ? | ? |