Files
Montech_Landing/apps/landing/plugins/lenis.client.ts
T

20 lines
466 B
TypeScript
Raw Normal View History

import Lenis from "lenis";
export default defineNuxtPlugin((nuxtApp) => {
if (!import.meta.client) return;
const lenis = new Lenis({ lerp: 0.09, smoothWheel: true });
let raf = 0;
const loop = (time: number) => {
lenis.raf(time);
raf = requestAnimationFrame(loop);
};
raf = requestAnimationFrame(loop);
nuxtApp.hook("app:unmounted", () => {
cancelAnimationFrame(raf);
lenis.destroy();
});
return {
provide: { lenis },
};
});