Created
May 5, 2021 07:30
-
-
Save wwwebman/4d9f9fa39f8dd1ee167dc17a404438f6 to your computer and use it in GitHub Desktop.
Revisions
-
wwwebman created this gist
May 5, 2021 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ 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; };