Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Your First Animation | Anime.js Essentials and Core Animation
JavaScript Animation with Anime.js

bookYour First Animation

index.html

index.html

copy

To create your first animation with Anime.js, you start by selecting the element you want to animate. In this case, you use a div with the id "box". This box is styled with a fixed width and height, a blue background, and an initial position on the page using CSS. The opacity is set to 0.5 so you can see the change as it animates.

Next, you include the Anime.js library by adding a script tag with its CDN link. This allows you to use Anime.js functions in your script.

The animation itself is triggered by calling the anime function. You pass in an object that describes what you want to animate:

  • The targets property specifies which element to animate. Here, you target the box using "#box";
  • You define the properties to animate. Setting left: '400px' moves the box horizontally, and opacity: 1 makes it fully visible;
  • The duration property sets how long the animation will take in milliseconds. Here, the animation lasts 2000 milliseconds (2 seconds);
  • The easing property controls the speed curve of the animation. Using 'easeInOutQuad' creates a smooth start and end.

When the script runs, Anime.js automatically animates the box: it slides from its original position to 400px from the left and fades in to full opacity.

1. When animating a box's position and opacity with Anime.js, which of the following is necessary?

2. Which property would you animate to make an element fade in or out?

question mark

When animating a box's position and opacity with Anime.js, which of the following is necessary?

Select the correct answer

question mark

Which property would you animate to make an element fade in or out?

Select the correct answer

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 1. Kapitel 2

Spørg AI

expand

Spørg AI

ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

Suggested prompts:

Can you show me the complete HTML and JavaScript code for this example?

How can I trigger the animation with a button click instead of running it automatically?

What other properties can I animate with Anime.js?

Awesome!

Completion rate improved to 5.88

bookYour First Animation

Stryg for at vise menuen

index.html

index.html

copy

To create your first animation with Anime.js, you start by selecting the element you want to animate. In this case, you use a div with the id "box". This box is styled with a fixed width and height, a blue background, and an initial position on the page using CSS. The opacity is set to 0.5 so you can see the change as it animates.

Next, you include the Anime.js library by adding a script tag with its CDN link. This allows you to use Anime.js functions in your script.

The animation itself is triggered by calling the anime function. You pass in an object that describes what you want to animate:

  • The targets property specifies which element to animate. Here, you target the box using "#box";
  • You define the properties to animate. Setting left: '400px' moves the box horizontally, and opacity: 1 makes it fully visible;
  • The duration property sets how long the animation will take in milliseconds. Here, the animation lasts 2000 milliseconds (2 seconds);
  • The easing property controls the speed curve of the animation. Using 'easeInOutQuad' creates a smooth start and end.

When the script runs, Anime.js automatically animates the box: it slides from its original position to 400px from the left and fades in to full opacity.

1. When animating a box's position and opacity with Anime.js, which of the following is necessary?

2. Which property would you animate to make an element fade in or out?

question mark

When animating a box's position and opacity with Anime.js, which of the following is necessary?

Select the correct answer

question mark

Which property would you animate to make an element fade in or out?

Select the correct answer

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 1. Kapitel 2
some-alt