Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

useScrollPrecent

import { useCallback, useEffect, useState } from 'react'

export default function useScrollPrecent() {
  const [scroll, setScroll] = useState(0)

  const handleScroll = useCallback(() => {
    setScroll(
      window.pageYOffset / (document.body.offsetHeight - window.innerHeight)
    )
  }, [])

  useEffect(() => {
    window.addEventListener('scroll', handleScroll, true)

    return () => window.removeEventListener('scroll', handleScroll)
  }, [handleScroll])

  return scroll
}

 
PREVIOUS NEXT
Tagged: #useScrollPrecent
ADD COMMENT
Topic
Name
9+6 =