23 lines
737 B
TypeScript
23 lines
737 B
TypeScript
"use client";
|
|
|
|
import { useEffect, useState } from "react";
|
|
|
|
export function ScrollProgress() {
|
|
const [w, setW] = useState(0);
|
|
useEffect(() => {
|
|
const onScroll = () => {
|
|
const h = document.documentElement;
|
|
const scrolled = (h.scrollTop / (h.scrollHeight - h.clientHeight)) * 100;
|
|
setW(Number.isFinite(scrolled) ? scrolled : 0);
|
|
};
|
|
onScroll();
|
|
window.addEventListener("scroll", onScroll, { passive: true });
|
|
return () => window.removeEventListener("scroll", onScroll);
|
|
}, []);
|
|
return (
|
|
<div className="pointer-events-none fixed left-0 top-0 z-[60] h-[2px] w-full">
|
|
<div className="h-full bg-[#6d5ef0] transition-[width] duration-100" style={{ width: `${w}%` }} />
|
|
</div>
|
|
);
|
|
}
|