How to create Timeline Animations using Anime.js ? Last Updated : 26 Jul, 2024 Comments Improve Suggest changes Like Article Like Report Anime.js is a lightweight JavaScript library with a simple and small powerful API. It works with the DOM element, CSS, and JavaScript object.PrerequisitesBasic knowledge of HTMLBasic knowledge of CSSBasic knowledge of JavaScriptInstallation of anime.js: There are two ways to use anime.js in your project:You can download the anime.min.js file and directly use it.Just google anime.js CDN and you will get the link and just put it in your script tag as shown below.<script src=”https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.0/anime.min.js”></script>Basic Properties used in anime.js:targets: The CSS Selectors to target and identify on which animation has to apply.duration: Time in milliseconds for which animation should last.delay: Time in milliseconds after which animation starts.translateX: Places element at that x coordinate.translateY: Places element at Y coordinate.offset: This gives a delay between different animations. i.e. to start another animation after x seconds of the previous one.Creating an application and Project structure: This is a simple web page. All we need to do is create a project and inside it create an HTML File named index.html.mkdir animation && cd animationtouch index.html Example 1: HTML <!DOCTYPE html> <html> <head> <title>A nice example for timeline</title> <script src= "https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.0/anime.min.js"> </script> <style> html { min-height: 200vh; } .ball { width: 60px; height: 60px; margin-top: 120px; margin-left: 200px; border-radius: 50%; background-color: pink; float: left; } </style> </head> <body> <div class="ball first"></div> <div class="ball second"></div> <div class="ball third"></div> <script> let animation = anime.timeline({ duration: 500, easing: 'easeInOutSine', direction: 'alternate', autoplay: false, loop: true }); animation.add({ targets: '.first', translateY: -50, backgroundColor: 'rgb(255, 0, 0)' }).add({ targets: '.second', translateY: -50, backgroundColor: 'rgb(0, 255, 0)' }).add({ targets: '.third', translateY: -50, backgroundColor: 'rgb(0, 0, 255)' }); window.onscroll = () => { animation.play(); } </script> </body> </html> Output: Example 2: In this example, the translateX property becomes more clear. It first translates into -ve x axis and then +ve x axis.index.html HTML <!DOCTYPE html> <html> <head> <title>A nice example for timeline</title> <script src= "https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.0/anime.min.js"> </script> <style> html { min-height: 200vh; } .ball { width: 200px; height: 200px; margin-top: 120px; margin-left: 200px; background-color: pink; float: left; } </style> </head> <body> <body> <div class="ball first"></div> <div class="ball second"></div> <div class="ball third"></div> <script> let animation = anime.timeline({ duration: 400, easing: 'easeInOutSine', direction: 'alternate', autoplay: false, loop: true }); animation.add({ targets: '.first', translateX: [-100, 100], backgroundColor: 'rgb(255, 0, 0)', }).add({ targets: '.second', translateX: [-100, 100], backgroundColor: 'rgb(0, 255, 0)', }).add({ targets: '.third', translateX: [-100, 100], backgroundColor: 'rgb(0, 0, 255)', }); window.onscroll = () => { animation.play() } </script> </body> </html> Output: Comment More infoAdvertise with us Next Article How to create Timeline Animations using Anime.js ? N namancourses Follow Improve Article Tags : JavaScript Web Technologies Anime.js JavaScript-Questions Similar Reads How to Create Text Animation Effect using JavaScript ? Creating text animations in JavaScript can add an extra layer of interactivity and engagement to a website or application. By using JavaScript, we can create text that moves, fades, changes color, or transforms in other ways. Animating text can also help convey important information or messages in a 2 min read How to create timeline using CSS? We can easily create a timeline using some basic HTML and CSS. HTML Code is used to create a basic structure of the timeline and CSS code is used to set the style. HTML Code: In this section, we will create a structure of our timeline. Our structure will include four events. Steps: Create a div elem 4 min read How to Create SVG Animations? Since web design is all about capturing the user's attention, it becomes necessary to use animation to communicate the value of our business/our client's business delightfully. This is why animations have become the go-to thing for designers to capture the visitor's attention or bring the visitor's 6 min read Text Animation using SVG Image What is SVG?SVG stands for Scalable Vector Graphics. It is an image format based on XML. It creates different geometric shapes that can be combined to make two-dimensional graphics.We are going to use an SVG image to create a text animation effect. The SVG images can be downloaded from the internet 15+ min read How to Use the Timeline in Animate? Flash is one of the best animation software choices for beginners as well as for professionals as it has great potential and is used in the creation of games, interactive webpages, animations, presentations, and much more. It has a simple interface that is totally customizable according to the prefe 6 min read Like