Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A relatively light-weight "scroll spy" to pivot scrolling events from edge → level.
{ // 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