Search
 
SCRIPT & CODE EXAMPLE
 

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
}

Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript declare variables 
Javascript :: javascript Implicit Conversion to String 
Javascript :: what f a number exceeding 2^53 in javascript 
Javascript :: eleventy filter newlines 
Javascript :: javascript variable hoisting 
Javascript :: javascript Access String Characters 
Javascript :: javascript Rethrow an Exception 
Javascript :: sign changely api 
Javascript :: javascript for...of with Maps 
Javascript :: javascript Deleting an object is not allowed 
Javascript :: JavaScript Comparison and Logical Operators 
Javascript :: actionscript fibonacci fibonaccinumbers 
Javascript :: salesforce set hours javascript 
Javascript :: javascript addall 
Javascript :: TypeError: _enzymeAdapterReact.EnzymeAdapter is not a constructor 
Javascript :: get html element coords with js 
Javascript :: Elementor Hide Sticky Header on Scroll Down - Show on Scroll Up 
Javascript :: phaser animation repeat event 
Javascript :: accessing-nested-javascript-objects-and-arrays-by-string-path 
Javascript :: on refresh action set position rainmeter 
Javascript :: get random hsl color js 
Javascript :: condition rendering using if-else 
Javascript :: Using the forEach function In JavaScript 
Javascript :: async await js 
Javascript :: password 
Javascript :: event listener 
Javascript :: vuejs accessing props from data 
Javascript :: react create context 
Javascript :: turn string into number javascript 
Javascript :: javascript array last element get 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =