Skip to content

Instantly share code, notes, and snippets.

@rjfranco
Created December 19, 2016 04:21
Show Gist options
  • Save rjfranco/774a033f6f3283b02d1366e0f3448070 to your computer and use it in GitHub Desktop.
Save rjfranco/774a033f6f3283b02d1366e0f3448070 to your computer and use it in GitHub Desktop.
Function to watch for scroll position and apply class
// Depends on JQ
window.addEventListener('scroll', function(e){
var distanceY = window.pageYOffset || document.documentElement.scrollTop,
transitionPoint = 500,
$header = $(".fixed-header");
if (distanceY > transitionPoint) {
$header.addClass("smaller");
} else {
$header.removeClass("smaller");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment