Currently, I am attempting to change the state and display a shadow in the navigation bar when the user scrolls, but for some reason it is not detecting the event.
I am working with nextJS 13 and tailwind css.
const [shadow, setShadow] = useState(false);
useEffect(() => {
const handleShadow = () => {
if (window.scrollY >= 90) {
setShadow(true);
} else {
setShadow(false);
}
window.addEventListener("scroll", handleShadow, true);
};
return window.removeEventListener("scroll", handleShadow);
}, []);
inside my HTML element
<div
className={
shadow
? "fixed left-0 top-0 w-full z-10 ease-in duration-300 bg-[#112240] shadow-xl"
: "fixed left-0 top-0 w-full z-10 ease-in duration-300 bg-[#112240]"
}
>
other code
</div>