Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

toggle class onscroll hook react

  const [scroll, setScroll] = useState(0)

  useEffect(() => {
    document.addEventListener("scroll", () => {
      const scrollCheck = window.scrollY < 100
      if (scrollCheck !== scroll) {
        setScroll(scrollCheck)
      }
    })
  })
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #toggle #class #onscroll #hook #react
ADD COMMENT
Topic
Name
9+7 =