animate() function is the primary way to create animations in Anime.js. It accepts targets and animation parameters, returning a new animation instance that automatically initializes and starts playing.
Signature
Parameters
The element(s) to animate. Can be:
- CSS selector string (e.g.,
'.my-element') - DOM element (e.g.,
document.querySelector('.my-element')) - NodeList or array of elements
- Plain JavaScript object
- Array of any combination of the above
Animation configuration object containing properties to animate and animation settings.
Return Value
Returns aJSAnimation instance with the following characteristics:
- Automatically initialized via
.init() - Starts playing immediately if
autoplayistrue(default) - Provides control methods (play, pause, restart, etc.)
- Extends the
Timerclass, inheriting all timer functionality
Examples
Basic Animation
Multiple Properties
Array Values (From-To)
Function-Based Values
With Callbacks
Keyframe Animation
Controlling the Animation
Notes
- The
animate()function is equivalent tonew JSAnimation(targets, parameters).init() - All animations are automatically added to the global animation engine
- Properties can use various value formats: numbers, strings with units, arrays, objects, or functions
- The returned animation instance is chainable and can be used with Promises via
.then()
Related
- Animation Class - Full Animation class documentation
- Animation Parameters - Detailed parameter reference