A Beginner's Guide to Using AOS Library with Next.js application
AOS stands for Animation on Scroll. It is a Javascript library that allows you to make a beautiful animation when a page is scrolled down or up on your website.
AOS library will help to enhance the visual appeal of your website with various types of animation such as fade-ins, and zoom-ins, ...
Some benefits when using the AOS library:
Using the AOS (Animate on Scroll) library with a Next.js application is relatively straightforward.
Before setting up AOS in your project, I would like to introduce AOS attributes:
Below is a beginner's guide to get you started:
First, install the AOS library in your Next.js project.
yarn add aos
In your Next.js project, you'll need to import AOS and initialize it.
// pages/_app.ts import { useEffect } from 'react'; import AOS from 'aos'; import 'aos/dist/aos.css'; const App = ({ children }) => { useEffect(() => { AOS.init({ // Global settings here }); }, []); return ( <div> {children} </div> ); }; export default App;
Now that AOS is initialized, you can use it in your components by adding AOS data attributes to the elements you want to animate:
// components/FadeUp.ts import React from 'react'; const FadeUp = () => { return ( <div data-aos="fade-up"> Content to animate </div> ); }; export default FadeUp;
Finally, start your Next.js application and test the AOS animations on scroll.
Overall, AOS is a useful tool for web developers and designers looking to add scroll-based animations to their websites without the need for complex coding or external libraries.
I hope this article gives more benefits to you.
Document references: