Answers for "add class in element on scroll"

0

add class in element on scroll

const [scroll, setScroll] = useState(false);
 useEffect(() => {
   window.addEventListener("scroll", () => {
     setScroll(window.scrollY > 50);
   });
 }, []);
Posted by: Guest on June-19-2021
0

add class in element on scroll

className={scroll ? "bg-black" : "bg-white"}
Posted by: Guest on June-19-2021

Code answers related to "add class in element on scroll"

Browse Popular Code Answers by Language