31 lines
689 B
TypeScript
31 lines
689 B
TypeScript
"use client";
|
|
|
|
import { useEffect } from "react";
|
|
import Lenis from "lenis";
|
|
import { gsap } from "gsap";
|
|
import { ScrollTrigger } from "gsap/ScrollTrigger";
|
|
|
|
gsap.registerPlugin(ScrollTrigger);
|
|
|
|
export default function SmoothScroll() {
|
|
useEffect(() => {
|
|
const lenis = new Lenis({
|
|
duration: 1.15,
|
|
smoothWheel: true,
|
|
easing: (t) => Math.min(1, 1.001 - Math.pow(2, -10 * t)),
|
|
});
|
|
|
|
lenis.on("scroll", ScrollTrigger.update);
|
|
|
|
const ticker = (time: number) => lenis.raf(time * 1000);
|
|
gsap.ticker.add(ticker);
|
|
gsap.ticker.lagSmoothing(0);
|
|
|
|
return () => {
|
|
gsap.ticker.remove(ticker);
|
|
lenis.destroy();
|
|
};
|
|
}, []);
|
|
|
|
return null;
|
|
}
|