Anime.js | Animation with different properties
Last Updated :
02 Jun, 2020
Anime.js is a small, lightweight JavaScript library with a simple and small powerful API. It works with DOM element, CSS and JavaScript object. Animation with CSS properties we can animate any CSS property. Below few of the examples are described with different CSS properties:
Example 1: First we have to set a target the div or element can be class or id, which we want to animate. The CSS background-color is one of the CSS property we are changing here from blue to #F75. The CSS border radius is another CSS property we are changing here. The we will use easing, easeInOutQuad mean just fading and showing, after that we will use the loop - true to keep repeating the animation. You can animate any css property here we showed backgroundColor and borderRadius.
html
<!DOCTYPE html>
<html>
<head>
<title>animejs</title>
<script src=
"https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.0/anime.min.js">
</script>
</head>
<body>
<center>
<h1 style="color: green;">GeeksforGeeks</h1>
<b>
Animation on background
color and border radius.
</b>
<br><br>
<div style="background: blue;
height: 80px;
width: 80px;">
</div>
</center>
<script>
let animation = anime({
targets: "div",
backgroundColor: "#F75",
borderRadius: "50px",
easing: "easeInOutQuad",
loop: true,
});
</script>
</body>
</html>
Output:
Example 2: In this example, we will animate with CSS transform. First, we have to set a target the div or element can be class or id, which we want to animate. The CSS translateX() function will set at 450 to move 450 into positive x-axis). We will use the CSS rotate() function to rotate - 720 degree. The CSS background-color is CSS property but not the part of CSS translate but we can use to change colour. The CSS direction property is set to alternate (move it back and fourth). Then the CSS duration is set for 2000 time for animation in ms) . after that we will use the loop - true to keep repeating the animation.
html
<!DOCTYPE html>
<html>
<head>
<title>animejs</title>
<script src=
"https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.0/anime.min.js">
</script>
</head>
<body>
<center>
<h1 style="color: green;">GeeksforGeeks</h1>
<b>
Animation on background
color and border radius.
</b>
<br><br>
</center>
<div style="background: blue;
height: 80px;
width: 80px;">
</div>
<script>
let animation = anime({
targets: "div",
// Move 250 into positive x-axis
translateX: 450,
// Degree you want to rotate
rotate: "720",
backgroundColor: "#f75",
direction: "alternate",
duration: "2000",
loop: true,
});
</script>
</body>
</html>
Output:
Example 3: Any Object property containing a numerical value can be animated. Here we just changed the value of object property and updated the dom and easing: linear is used to animate it linearly and you can change the round value to see what it is used for.
html
<!DOCTYPE html>
<html>
<head>
<title>animejs</title>
<script src=
"https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.0/anime.min.js">
</script>
</head>
<body>
<div></div>
<script>
var div = document.querySelector("div");
var object = {
prop1: 10,
prop2: "0%",
};
let animation = anime({
targets: object,
prop1: 70,
prop2: "96%",
easing: "linear",
round: 1,
update: function () {
div.innerHTML = JSON.stringify(object);
},
});
</script>
</body>
</html>
Output:
Example 4: Here, values will contain from value - to value( Dom Attribute ). Such as value inside the input field (numeric)
html
<!DOCTYPE html>
<html>
<head>
<title>animejs</title>
<script src=
"https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.0/anime.min.js">
</script>
</head>
<body>
<input style="text-align: center;" type="text" />
<script>
let animation = anime({
targets: "input",
value: [0, 100],
round: 1,
easing: "easeInOutExpo",
});
</script>
</body>
</html>
Output:
Example 5: In this example we will animate SVG attribute. We created a circle of radius 50 centre at position 150, 150, then we applied anime on circle moved the centre to 200, 200 and made radius 60.
html
<!DOCTYPE html>
<html>
<head>
<title>animejs</title>
<script src=
"https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.0/anime.min.js">
</script>
</head>
<body>
<center>
<h1 style="color: green;">GeeksforGeeks</h1>
<b>
SVG Attribute
</b>
<br><br>
<svg height="400" width="400">
<circle cx="50" cy="50" r="40"
stroke="black" stroke-width="2"
fill="green"/>
</svg>
</center>
<script>
let animation = anime({
targets: ["circle"],
cx: "300",
cy: "300",
r: "60",
baseFrequency: 0,
scale: 1,
loop: true,
direction: "alternate",
easing: "easeInOutExpo",
});
</script>
</body>
</html>
Output:
Similar Reads
JavaScript Tutorial JavaScript is a programming language used to create dynamic content for websites. It is a lightweight, cross-platform, and single-threaded programming language. It's an interpreted language that executes code line by line, providing more flexibility.JavaScript on Client Side: On the client side, Jav
11 min read
JavaScript Interview Questions and Answers JavaScript is the most used programming language for developing websites, web servers, mobile applications, and many other platforms. In Both Front-end and Back-end Interviews, JavaScript was asked, and its difficulty depends upon the on your profile and company. Here, we compiled 70+ JS Interview q
15+ min read
Introduction to JavaScript JavaScript is a versatile, dynamically typed programming language used for interactive web applications, supporting both client-side and server-side development, and integrating seamlessly with HTML, CSS, and a rich standard library.JavaScript is a single-threaded language that executes one task at
7 min read
JSON Web Token (JWT) A JSON Web Token (JWT) is a standard used to securely transmit information between a client (like a frontend application) and a server (the backend). It is commonly used to verify users' identities, authenticate them, and ensure safe communication between the two. JWTs are mainly used in web apps an
7 min read
Frontend Developer Interview Questions and Answers Frontend development is an important part of web applications, and it is used to build dynamic and user-friendly web applications with an interactive user interface (UI). Many companies are hiring skilled Frontend developers with expertise in HTML, CSS, JavaScript, and modern frameworks and librarie
15+ min read
JavaScript Coding Questions and Answers JavaScript is the most commonly used interpreted, and scripted Programming language. It is used to make web pages, mobile applications, web servers, and other platforms. Developed in 1995 by Brendan Eich. Developers should have a solid command over this because many job roles need proficiency in Jav
15+ min read
Top 95+ Javascript Projects For 2025 JavaScript is a lightweight, cross-platform programming language that powers dynamic and interactive web content. From real-time updates to interactive maps and animations, JavaScript brings web pages to life.Here, we provided 95+ JavaScript projects with source code and ideas to provide hands-on ex
4 min read
Functions in JavaScript Functions in JavaScript are reusable blocks of code designed to perform specific tasks. They allow you to organize, reuse, and modularize code. It can take inputs, perform actions, and return outputs.JavaScriptfunction sum(x, y) { return x + y; } console.log(sum(6, 9)); // output: 15Function Syntax
5 min read
JavaScript Exercises, Practice Questions and Solutions JavaScript Exercise covers interactive quizzes, tracks progress, and enhances coding skills with our engaging portal. Ideal for beginners and experienced developers, Level up your JavaScript proficiency at your own pace. Start coding now! A step-by-step JavaScript practice guide for beginner to adva
3 min read
HTML DOM (Document Object Model) The HTML DOM (Document Object Model) is a programming interface that represents the structure of a web page in a way that programming languages like JavaScript can understand and manipulate. Think of it as a tree of objects where each part of your HTML document (elements, attributes, text) is repres
6 min read