Introduction to Anime.js

DZone 's Guide to

Introduction to Anime.js

Want to use your web development and JavaScript knowledge to bring out your inner artist? Take at look at Anime.js, a library built to create animations using JavaScript.

· Web Dev Zone ·
Free Resource

JavaScript animation has been around for a while. There is a wide choice of JavaScript animation libraries for you to try out. Among that group, Anime.js has been gaining some significant popularity. If you’re not familiar with it, I hope this article will get you started with this lightweight and flexible animation library.

This library works with any CSS Properties, individual CSS transforms, SVG, or any DOM attributes, and JavaScript Objects.

Let's create some animations using Anime.js.


Download the library from GitHub or link it through cdnjs. If you are using npm or bower, you can do as follows:

npm install animejs


bower install animejs

Then in your script file:

import anime from 'animejs'

Let’s add the following code snippet into our HTML <body>:

<div class="purple"></div>
<div class="darkgreen"></div>
<div class="darkred"></div>

Creating Animations

The first step is to initialize the anime object:

//properties here

Within the object above, we will provide certain properties to instruct what and how the elements should animate.

  targets: ['.purple', '.darkgreen', '.darkred'],
  translateX: '25rem',
  rotate: 360,
  borderRadius: '50%',
  duration: 3000,
  loop: true

Here, the 'targets' property defines the elements to animate. The property 'translateX' moves the elements in a horizontal direction. The property 'duration' defines how long the animation lasts. 

The 'loop' property runs the animation indefinitely if it is set to true. If it is set to false, it runs just once. 

Check out the complete demo on CodePen.

Wrapping Up

Working with Anime.js is easy and fun. It lets you create smooth animations and the API is easy to follow. It offers a lot of cool features. If you wish to explore it further, check out the documentation and examples here. I hope you will enjoy working with Anime.js!

javascript ,web dev ,animations ,javascript libraries

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}