Aos: How to mix AOS and Next.js ?

Created on 23 Apr 2020  路  8Comments  路  Source: michalsnik/aos

This is:

  • Question


Specifications

  • AOS version: last
  • OS: Windows 10
  • Browser: Chrome

Expected Behavior


Animation working directly

Actual Behavior


Animation works only when I open the dev console (I think it's because it's SSR)

Steps to Reproduce the Problem



  1. 2.
    3.

Detailed Description

Possible Solution

Most helpful comment

adding something like this in pages/_app.js works for me:

import { useEffect } from "react";
import AOS from "aos";

import "aos/dist/aos.css";
import "../scss/style.scss";

function MyApp({ Component, pageProps }) {
  useEffect(() => {
    AOS.init({
      easing: "ease-out-cubic",
      once: true,
      offset: 50,
    });
  }, []);

  return <Component {...pageProps} />;
}

export default MyApp;

All 8 comments

Having same issues.
It only works on dev environment and doesn't display anything in production

How did you guys get it to work (even in dev) with NextJs?

I get the initial load animation, but nothing happens on scroll. When i inspect my elements, the aos-init class is added, but aos-animate isn't being added on scroll.

How did you guys get it to work (even in dev) with NextJs?

I get the initial load animation, but nothing happens on scroll. When i inspect my elements, the aos-init class is added, but aos-animate isn't being added on scroll.

When page is loaded, just open the devtools and close it. It should make the scroll work.

Where and when are you initializing aos? Try initializing aos in an effect in _app.js.

Up!
Hi guys, I am also trying to integrate AOS with next js.
-J

adding something like this in pages/_app.js works for me:

import { useEffect } from "react";
import AOS from "aos";

import "aos/dist/aos.css";
import "../scss/style.scss";

function MyApp({ Component, pageProps }) {
  useEffect(() => {
    AOS.init({
      easing: "ease-out-cubic",
      once: true,
      offset: 50,
    });
  }, []);

  return <Component {...pageProps} />;
}

export default MyApp;

@knowbody I'll try to implement it tomorrow and I will let you know how it goes. Does is also work in production ?

@knowbody thank you, works perfectly. I think we can close this issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

luminawastaken picture luminawastaken  路  3Comments

meko-deng picture meko-deng  路  4Comments

webcredo picture webcredo  路  3Comments

hockey2112 picture hockey2112  路  4Comments

simmonsr picture simmonsr  路  4Comments