Last active
September 9, 2020 13:16
-
-
Save luisfelipe-dev/fc2d0a0ad7d698cdd7213329beab08aa 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 headerElement = useRef(null); | |
useEffect(() => { | |
window.onscroll = () => { | |
const headerScrollPosition = headerElement.current.scrollTop + headerElement.current.clientHeight; | |
if (window.scrollY >= headerScrollPosition) { | |
setScrolled(true); | |
} else { | |
setScrolled(false); | |
} | |
} | |
return () => { | |
window.onscroll = () => {}; | |
} | |
}, [ | |
open, | |
scrolled | |
]); | |
<Style.Header ref={ headerElement } className={ scrolled ? 'app-fixed-top' : '' }> | |
position: fixed; | |
top: 0; | |
left: 0; | |
right: 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment