Last active
December 31, 2015 08:09
-
-
Save dannyconnolly/7958593 to your computer and use it in GitHub Desktop.
Requires classie.js https://github.com/ded/bonzo
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 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