AOS.js (Scroll Animation) is a JavaScript library that provides animations, making it easier just by changing the class name in the desired div tag Add a lot of animations to add animations. While there are different animation JavaScript libraries, AOS.js is probably the simplest of them all.
In this tutorial, we will explore the different types of animations that can be used in AOS.js with the help of different examples.
The first type of animation we will explore is the fade animation. Before doing that, we first need to make sure that aos.css and aos.js are available in our code and that we can get them via a CDN link.
Simply paste the following code snippet at the end of the
tag in your HTML code.<link rel="stylesheet" href="https://unpkg.com/aos@next/dist/aos.css" />
The above code snippet will help to get the css file, in order to get the js file we need to paste the CDN code snippet as shown below at the end of the body tag in the HTML code .
<script src="https://unpkg.com/aos@next/dist/aos.js"></script> <script> AOS.init(); </script>
After adding the above two code snippets to the HTML code, we can use AOS in the code.
Use AOS.js fade animation
The fade-in and fade-out animation simulates the fade-in and fade-out behavior, and a total of 8 different animations can be achieved. these are -
fade in and fade out
fade in and fade out
Fade left
Fade right
Fade left
Fade right
Fade left
Fade left
Now let’s use them one by one in a simple HTML-CSS example.
The code snippet below is the only part where we will make changes to all the above fade animations.
<div id="main"> <div data-aos="fade-up">Something up!</div> </div>
In the above code, we pass the value as "fade-up" to the data-aos attribute, and in all fade cases, only this value will be changed.
index.html
Now, let's consider the following index.html file where we will perform a "fade out" animation.
Example
AOS - Animation <link rel="stylesheet" href="https://unpkg.com/aos@next/dist/aos.css" /><script> AOS.init(); </script>Something Up!
When you run the above code in your browser, you should see a div containing the text "Something Up!" appearing in an upward direction with a fade animation.
Similarly, if we want to perform a fade animation, we can use the one shown in the code snippet below.
<div id="main"> <div data-aos="fade-down">Something down!</div> </div>
We only need to replace the div in the index.html file with the above div to get the fade animation.
For Fade to the left, the code snippet looks like this.
<div id="main"> <div data-aos="fade-left">Something left!</div> </div>
For the fade, the code snippet is as follows.
<div id="main"> <div data-aos="fade-right">Something right!</div> </div>
For Fade-up-left, the code snippet is shown below.
<div id="main"> <div data-aos="fade-up-left">Something up left!</div> </div>
For Fade-up-right, the code snippet is shown below.
<div id="main"> <div data-aos="fade-up-right">Something up right!</div> </div>
For Fade left, the code snippet looks like this.
<div id="main"> <div data-aos="fade-down-left">Something down left!</div> </div>
For Fade-down-right, the code snippet is shown below.
<div id="main"> <div data-aos="fade-down-right">Something down right!</div> </div>
At this point, we can conclude that the fade animation in AOS has been completed.
Use AOS.js flip animation
Flip animation simulates flipping behavior, and a total of 4 different animations can be achieved. these are -
On the turn
Turn down
Flip left
Turn right
Now let’s use them one by one in a simple HTML-CSS example.
index.html
Let's consider the following index.html file where we will perform a "flip up" animation.
AOS - Animation <link rel="stylesheet" href="https://unpkg.com/aos@next/dist/aos.css" /><script> AOS.init(); </script>Flip Up!
When you run the above code in your browser, you should see a div with the text "Flip Up!" Appears with a flip animation in the upward direction.
Similarly, if we want to do a flip-down animation, we can use the one shown in the code snippet below.
<div id="main"> <div data-aos="flip-down">Flip down!</div> </div>
For left flipping, the code snippet is as follows.
<div id="main"> <div data-aos="flip-left">Flip left!</div> </div>
For right flipping, the code snippet is as follows.
<div id="main"> <div data-aos="flip-right">Flip right!</div> </div>
Using AOS.js scaling animation
Zoom animation simulates zoom behavior, and a total of 8 different animations can be achieved. these are -
- enlarge
- enlarge
- Zoom
- Zoom left
- Zoom right
- Zoom
- enlarge
- Zoom
- Zoom left
- Zoom right
Now let’s use them one by one in a simple HTML-CSS example.
index.html
Let us consider the following index.html file where we will perform a "zoom in" animation.
Example
AOS - Animation <link rel="stylesheet" href="https://unpkg.com/aos@next/dist/aos.css" /><script> AOS.init(); </script>Zoom in!
When we run the above code in the browser, we should see a div with the Text Zoom pointing upwards in its zoom animation.
Similarly, if we want to perform a zoom-in animation, we can use the one shown in the code snippet below.
<div id="main"> <div data-aos="zoom-in-up">Zoom in up!</div> </div>
For zoom, the code snippet is shown below.
<div id="main"> <div data-aos="zoom-in-down">Zoom in down!</div> </div>
For Zoom to the left, the code snippet looks like this.
<div id="main"> <div data-aos="zoom-in-left">Zoom in left!</div> </div>
For zoom to the right, the code snippet looks like this.
<div id="main"> <div data-aos="zoom-in-right">Zoom in right!</div> </div>
同样,如果我们想要缩小动画,我们可以使用下面代码片段中显示的。
<div id="main"> <div data-aos="zoom-out">Zoom out!</div> </div>
对于放大,代码片段如下所示。
<div id="main"> <div data-aos="zoom-out-up">Zoom out up!</div> </div>
对于缩小,代码片段如下所示。
<div id="main"> <div data-aos="zoom-out-down">Zoom out down!</div> </div>
对于向左缩小,代码片段如下所示。
<div id="main"> <div data-aos="zoom-out-left">Zoom out left!</div> </div>
对于向右缩小,代码片段如下所示。
<div id="main"> <div data-aos="zoom-out-right">Zoom out right!</div> </div>
使用 AOS.js 进行多重设置动画
在上面的所有示例中,我们使用的是单个动画,没有其他选项,但 AOS.js 也允许我们使用带有动画的选项。例如,考虑这样的情况:我们想要一个淡入淡出动画,但持续时间为某个时间。
在下面的代码片段中,我们将创建一个带有持续时间的淡入淡出动画。
<div id="main"> <div data-aos="fade-down" data-aos-duration="3000"></div>>Fade Down With Duration!</div> </div>
结论
在本教程中,我们演示了如何借助 AOS.js、HTML 和 CSS 创建滚动动画。
The above is the detailed content of Add animation on scroll using HTML, CSS and AOS.js. For more information, please follow other related articles on the PHP Chinese website!

Detailed explanation of JavaScript string replacement method and FAQ This article will explore two ways to replace string characters in JavaScript: internal JavaScript code and internal HTML for web pages. Replace string inside JavaScript code The most direct way is to use the replace() method: str = str.replace("find","replace"); This method replaces only the first match. To replace all matches, use a regular expression and add the global flag g: str = str.replace(/fi

So here you are, ready to learn all about this thing called AJAX. But, what exactly is it? The term AJAX refers to a loose grouping of technologies that are used to create dynamic, interactive web content. The term AJAX, originally coined by Jesse J

10 fun jQuery game plugins to make your website more attractive and enhance user stickiness! While Flash is still the best software for developing casual web games, jQuery can also create surprising effects, and while not comparable to pure action Flash games, in some cases you can also have unexpected fun in your browser. jQuery tic toe game The "Hello world" of game programming now has a jQuery version. Source code jQuery Crazy Word Composition Game This is a fill-in-the-blank game, and it can produce some weird results due to not knowing the context of the word. Source code jQuery mine sweeping game

This tutorial demonstrates how to create a captivating parallax background effect using jQuery. We'll build a header banner with layered images that create a stunning visual depth. The updated plugin works with jQuery 1.6.4 and later. Download the

Article discusses creating, publishing, and maintaining JavaScript libraries, focusing on planning, development, testing, documentation, and promotion strategies.

The article discusses strategies for optimizing JavaScript performance in browsers, focusing on reducing execution time and minimizing impact on page load speed.

Matter.js is a 2D rigid body physics engine written in JavaScript. This library can help you easily simulate 2D physics in your browser. It provides many features, such as the ability to create rigid bodies and assign physical properties such as mass, area, or density. You can also simulate different types of collisions and forces, such as gravity friction. Matter.js supports all mainstream browsers. Additionally, it is suitable for mobile devices as it detects touches and is responsive. All of these features make it worth your time to learn how to use the engine, as this makes it easy to create a physics-based 2D game or simulation. In this tutorial, I will cover the basics of this library, including its installation and usage, and provide a

This article demonstrates how to automatically refresh a div's content every 5 seconds using jQuery and AJAX. The example fetches and displays the latest blog posts from an RSS feed, along with the last refresh timestamp. A loading image is optiona


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version
Chinese version, very easy to use

Dreamweaver Mac version
Visual web development tools