Last active
November 2, 2021 16:04
-
-
Save kate0n/ed2d33f14458b986e60e090a609b1d7c to your computer and use it in GitHub Desktop.
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 characters
| const [y, setY] = useState(window.scrollY); | |
| const handleNavigation = useCallback( | |
| (e) => { | |
| const window = e.currentTarget; | |
| if (y > window.scrollY) { | |
| console.log("scrolling up"); | |
| setHeaderHidden(false); | |
| } else if (y - window.scrollY < -10) { | |
| setHeaderHidden(true); | |
| console.log("scrolling down"); | |
| } | |
| setY(window.scrollY); | |
| console.log("y", y, height); | |
| }, | |
| [y], | |
| ); | |
| useEffect(() => { | |
| setY(window.scrollY); | |
| window.addEventListener("scroll", handleNavigation); | |
| return () => { | |
| window.removeEventListener("scroll", handleNavigation); | |
| }; | |
| }, [handleNavigation]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment