Created
March 28, 2022 05:39
-
-
Save amcgregor/5b479dbf167a244454780434a12885be to your computer and use it in GitHub Desktop.
A relatively light-weight "scroll spy" to pivot scrolling events from edge → level.
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
{ // Detect scrolling of the viewport away from the absolute top of the document. | |
function scrollHandler(e) { | |
if ( window.scrollY == 0 && document.body.scrollTop == 0 ) document.body.classList.remove('offset') | |
else document.body.classList.add('offset') | |
} | |
// Watch for the page being scrolled. | |
window.addEventListener('scroll', scrollHandler) | |
document.body.addEventListener('scroll', scrollHandler) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment