Last active
January 26, 2016 16:19
-
-
Save iforwms/5c69d4843747d83c67ec to your computer and use it in GitHub Desktop.
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
var didScroll = false; | |
var html = document.body.parentNode; | |
var scrollOffset = 500; | |
var scrollingClass = 'scrolling'; | |
window.onscroll = addClassToHtml; | |
function addClassToHtml() { | |
didScroll = true; | |
} | |
setInterval(function() { | |
if(didScroll) { | |
didScroll = false; | |
var scroll = window.pageYOffset; | |
if (scroll >= scrollOffset) { | |
html.classList.add(scrollingClass); | |
} | |
else { | |
html.classList.remove(scrollingClass); | |
} | |
} | |
}, 100); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment