Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 7362

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 60k
Author
Asked: November 28, 20242024-11-28T03:05:12+00:00 2024-11-28T03:05:12+00:00

Animation Techniques with anime.js: Timing, Easing, and Keyframes

  • 60k

Welcome to the second tutorial in this series on animating with anime.js! In the previous post, “Become an Animation Master with Anime.js – Setting up the Environment and Basic Animations“, we went through setting up the environment for creating animations with anime.js and I explained the basics with different examples.

In this tutorial, we'll cover some advanced techniques for timing, easing, and keyframes in anime.js.

Before we move on, remember you can build your websites, landing pages, APIs, and more, with or without coding on DoTenX for free. Make sure to check it out and even nominate your work to be showcased.DoTenX is open-source and you can find the repository here: github.com/dotenx/dotenx.


Timing

Timing is one of the key aspects of animation. In anime.js, you can use the duration property (in milliseconds) to specify the length of an animation. We can also use the delay property which is also in milliseconds, to specify a delay before the animation starts.

For example, let's say you want to animate an element's position from left to right over the course of 1 second, with a delay of half a second before the animation starts:

<div id="#box"></div> 
Enter fullscreen mode Exit fullscreen mode

#box {   margin-left: 200px;   margin-top: 200px;   width: 100px;   height: 100px;   background: blue; } 
Enter fullscreen mode Exit fullscreen mode

anime({   targets: '#my-element',   translateX: ['0px', '200px'],   duration: 1000,  // 1 second   delay: 500,  // half a second }); 
Enter fullscreen mode Exit fullscreen mode

We can also use the loop property to specify that the animation should loop indefinitely.

anime({   targets: '#box',   translateX: ['0px', '200px'],   duration: 1000,   loop: true, }); 
Enter fullscreen mode Exit fullscreen mode

Easing

We mentioned the timing and now let's take a look at another very important aspect of animation, easing. In simple terms, easing refers to the way the animation accelerates and decelerates over time. In anime.js, we have a property named easing that we can use to specify the easing function to use for the animation.

Anime.js offers a long list of built-in easing functions such as 'linear', 'easeInQuad', and 'easeOutQuad'. Usually, the default options are good enough, but you can also use the bezier function to create custom easing curves.

You can find the complete list here.

For example, let's animate an element's position using a custom easing curve:

anime({   targets: '#box',   translateX: ['0px', '200px'],   duration: 1000,   easing: anime.bezier(0.5, 0, 0.5, 1), }); 
Enter fullscreen mode Exit fullscreen mode

This will animate the element's position using a custom easing curve that starts and ends slowly, with a faster rate of change in the middle.

Keyframes

Keyframes refer to states in our animations. So far we have use the default behaviour which starts with a default from value and animates the element by updating the value to get to the so-called to value.

However, in anime.js, we can specify a series of intermediate states for the animation and create complex animations.

For example, let's say you want to animate an element's position from left to right, with a bounce at the end:

anime({   targets: '#box',   translateX: [     {value: '0px', duration: 1000},  // starting position     {value: '200px', duration: 1000},  // intermediate position     {value: '100px', duration: 500},  // bounce position     {value: '300px', duration: 1000},  // ending position   ],   easing: 'easeInOutQuad', }); 
Enter fullscreen mode Exit fullscreen mode

This will animate the element's position from 0px to 300px over the course of 4 seconds, with a bounce at the 200px position. The animation is using the easeInOutQuad easing function for all the keyframes and different durations for each keyframe. We could also set different delays or easing functions for each keyframe.

We can also set multiple properties at the same time in each keyframe. For example, let's animate the element's position and opacity simultaneously:

anime({   targets: '#box',   translateX: [     {value: '0px', duration: 1000},     {value: '200px', duration: 1000},   ],   opacity: [     {value: 0, duration: 1000},     {value: 1, duration: 1000},   ],   easing: 'easeInOutQuad',  }); 
Enter fullscreen mode Exit fullscreen mode

Another way to create keyframes is to use the keyframes property to specify the intermediate states.

Let's take a look at an example using the keyframes property.

anime({   targets: '#box',   keyframes: [     {translateX: 300},     {translateX: 0},     {translateX: 200},     {translateX: 100},   ],   duration: 3000,   easing: 'easeOutQuad',   direction: 'alternate',   loop: true }); 
Enter fullscreen mode Exit fullscreen mode


In the next tutorial, we'll go through advanced animations with anime.js with a focus on chaining, sequencing, and staggering, so stay tuned.

Don't forget to visit DoTenX and soon a dedicated animation section will be added to the platform allowing you to create amazing animations with the concepts you learned here. Keep an eye on the Github repository for the new release.

codenewbiecsshtmlwebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 1k
  • Popular
  • Answers
  • Author

    How to ensure that all the routes on my Symfony ...

    • 0 Answers
  • Author

    Insights into Forms in Flask

    • 0 Answers
  • Author

    Kick Start Your Next Project With Holo Theme

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.