Skip to content
Advertisement

How can I chain animations in anime.js?

Is there any way to chain animations in anime.js or have queues / groups of animations that I can wait for in order to proceed with other animations?

Advertisement

Answer

Each animation with anime returns a promise, so you can use async/await in combination with Promise.all, do remember, though, Promise.all makes it so that all animations run concurrently. For example, let’s say you want 3 animations all to run at the same time, then, after that group is done, do another animation:

JavaScript
JavaScript
JavaScript

What, then, if you want to, inside that function, have the lock-line animate at the same time the 2 other elements are animating, so instead of 3 animation timelines, you only have 2? Here:

JavaScript

We moved that lock-line animation outside of the original group, made it wait for the group, then whatever else comes after the lock-line animates after.

You should think about an animation as a simple promise that you can chain.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement