"use client"; import { useEffect } from "react"; export default function ScrollTop() { useEffect(() => { const box = document.querySelector(".scrollTop"); const liquid = document.querySelector(".liquid"); const offset = 200; const handleScroll = () => { const scrollPosition = window.scrollY; const docHeight = document.documentElement.scrollHeight - window.innerHeight; const percent = Math.min( Math.floor((scrollPosition / docHeight) * 100), 100 ); if (liquid) { liquid.style.transform = `translate(0, ${100 - percent}%)`; } if (scrollPosition >= offset) { box?.classList.add("active-progress"); } else { box?.classList.remove("active-progress"); } }; const handleClick = (event) => { event.preventDefault(); window.scrollTo({ top: 0, behavior: "smooth" }); }; window.addEventListener("scroll", handleScroll); box?.addEventListener("click", handleClick); return () => { window.removeEventListener("scroll", handleScroll); box?.removeEventListener("click", handleClick); }; }, []); return (