"use client"; import { useEffect, useState } from "react"; export default function ScrollProgress() { const [progress, setProgress] = useState(0); useEffect(() => { const onScroll = () => { const scrollTop = window.scrollY; const docHeight = document.documentElement.scrollHeight - window.innerHeight; setProgress(docHeight > 0 ? Math.min((scrollTop / docHeight) * 100, 100) : 0); }; window.addEventListener("scroll", onScroll, { passive: true }); onScroll(); return () => window.removeEventListener("scroll", onScroll); }, []); return (
); }