I am using NEXT JS 13 with 'app' dir, within it with the help of loader.tsx and page.tsx I'm trying to create a number % loading animation using gsap, but there is no rendering of data from loading.tsx file and I'm can't able to identify the problem with my code.
link to demo file - https://stackblitz.com/edit/stackblitz-starters-wlywtf?embed=1&file=app%2Floading.tsx
I want loading animation similar to this.
reference - DuallStudio . Creative Digital Studio
page.tsx -
export default async function Home() {
await new Promise((resolve) => setTimeout(resolve, 3000));
return (
<main>
<section className="flex justify-start">
<span className="text-7xl relative">
Hello <br /> there <span className="absolute top">👋</span>
</span>
</section>
</main>
);
}
loading.tsx -
// Loading.js
'use client'
import { useEffect } from 'react';
import gsap from 'gsap';
const Loading = () => {
useEffect(() => {
const tl = gsap.timeline({ repeat: -1 });
tl.to('.preloader', {
width: '100%',
duration: 1,
ease: 'power1.inOut',
}).to('.preloader', { width: '0%', duration: 1, ease: 'power1.inOut' });
}, []);
return (
<div className="fixed flex justify-center items-center w-screen h-screen z-[1000]">
<div className="preloader"></div>
</div>
);
};
export default Loading;