Skip to content

Instantly share code, notes, and snippets.

@dannyconnolly
Last active December 31, 2015 08:09
Show Gist options
  • Save dannyconnolly/7958593 to your computer and use it in GitHub Desktop.
Save dannyconnolly/7958593 to your computer and use it in GitHub Desktop.
Requires classie.js https://github.com/ded/bonzo
var animatedHeader = (function() {
var docElem = document.documentElement,
header = document.querySelector( '.site-header' ),
didScroll = false,
changeHeaderOn = 1;
function init() {
window.addEventListener( 'scroll', function( event ) {
if( !didScroll ) {
didScroll = true;
setTimeout( scrollPage, 250 );
}
}, false );
}
function scrollPage() {
var sy = scrollY();
if ( sy >= changeHeaderOn ) {
classie.add( header, 'shrink' );
}
else {
classie.remove( header, 'shrink' );
}
didScroll = false;
}
function scrollY() {
return window.pageYOffset || docElem.scrollTop;
}
init();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment