Hi there,
I am working on a Next V13(using App Router) project and tried to use ScrollSmoother for smooth scrolling of the page.
But unable to make it work. On checking the console, can see a warning of ScrollSmoother needs a valid content element.
The screenshot is attached.
We used ScrollSmoother on Next V12 which is working seamlessly. I followed the same coding standard on the new project.
Due to the privacy concern of the project, I cannot create a CodePen example.
Example coding as below to give an idea:
app/layout.js
'use client'
import './css/globals.css'
import { gsap } from "gsap";
import { ScrollTrigger } from "gsap/dist/ScrollTrigger";
import { ScrollSmoother } from "gsap/dist/ScrollSmoother";
import { useRef, useEffect, useState } from "react";
export default function RootLayout({ children }) {
gsap.registerPlugin(ScrollTrigger, ScrollSmoother);
useEffect(() => {
ScrollSmoother.create({
content: "#smooth-content",
smooth: 3,
effects: false,
normalizeScroll: true,
});
}, []);
return (
<html lang="en-nz">
<body suppressHydrationWarning={true}>
{children}
</body>
</html>
)
}
/app/page.js
export default async function Home() {
return (
<main className="tw-relative">
<NavBar navData={navData} /> {/* fixed element...*/}
<div id="smooth-wrapper">
<div id="smooth-content">
{/* rest of code...*/}
</div>
</div>
</main>
)
}
Any help would be appreciated.