animate()
Introduction
Use animate() to set a CSS Animation on UI elements.
- Use the getElementById API to find the
Elementobject that needs to be animated based on itsid. - Call the
animateAPI on theElementobject to achieve animation.
Syntax
Parameter
keyframes
There are two different formats:
- An array consisting of objects that contain properties and values of multiple keyframes.
- An object consisting of keys as offsets and values as keyframes.
- You can also assign a timing-function for each keyframe.
options
An object that contains one or more properties:
- If no
nameis specified, a unique id is generated incrementally. - An animation with the same
namecannot be triggered consecutively multiple times.
Return Value
Returns an Animation object.
The Animation object has the following methods:
Example
by getElementById()
- Each call to
getElementById("test").animatewill generate a newAnimationobject, and the later created animation will override the previous ones. - If you want to restart the same animation, you need to call
getElementById("test").animateagain to create a newAnimationobject.
by createSelectorQuery() 3.4
After Lynx version 3.4, the animate() can be called via the createSelectorQuery().
It's an experimental feature, and you should use it with caution.
Multiple animate 3.4
After Lynx version 3.4, you can chain multiple animation with createSelectorQuery().
It's an experimental feature, and you should use it with caution.
Animation Event
The events for the animate() API are the same as the animation events for CSS animations.
Other Infos
-
Animate Api and CSS Animation will override each other, and the one that takes effect later will override the former.
-
The Animate API may not take effect, possibly because
getElementByIdfailed to select the node:- The ID selector might be incorrect
- The value of the ID selector might depend on a complex JS expression, causing the value of the ID selector not to be available on the first screen. In this case, if getElementById is invoked too early (like in ComponentDidMount), it might not find the node.
See also
Compatibility
LCD tables only load in the browser