Skip to content

Instantly share code, notes, and snippets.

@iforwms
Last active January 26, 2016 16:19
Show Gist options
  • Save iforwms/5c69d4843747d83c67ec to your computer and use it in GitHub Desktop.
Save iforwms/5c69d4843747d83c67ec to your computer and use it in GitHub Desktop.
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