Created
May 5, 2021 07:30
-
-
Save wwwebman/4d9f9fa39f8dd1ee167dc17a404438f6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const handleScroll = () => { | |
const pageYOffset = window.pageYOffset; | |
const windowHeight = window.innerHeight; | |
const elementOffsetTop = ref?.current?.offsetTop ?? 0; | |
const elementHeight = ref?.current?.offsetHeight ?? 0; | |
const scrollDirectionToTop = pageYOffset < prevPageYOffset.current; | |
const distanceFromTop = pageYOffset + elementOffsetTop; | |
const inViewport = | |
pageYOffset >= elementOffsetTop - windowHeight && | |
pageYOffset <= elementOffsetTop + elementHeight; | |
if (inViewport) {} | |
prevPageYOffset.current = pageYOffset; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment