Skip to content

Instantly share code, notes, and snippets.

@rfmeier
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rfmeier/c421a5bf60ec886a38a1 to your computer and use it in GitHub Desktop.
Save rfmeier/c421a5bf60ec886a38a1 to your computer and use it in GitHub Desktop.
Show menu based on scroll position.
( function($) {
$( document ).ready( function () {
var primaryNav = $( 'body.home' ).find( 'nav.nav-primary' );
// check initial window size
if( window.innerWidth > 687 ) {
primaryNav.hide();
}
// listen for scroll event
$( window ).on( 'scroll', function(){
// if screen size is less than 688, return
if( window.innerWidth < 688 ) {
return;
}
if ( $( this ).scrollTop() > 150 ){
primaryNav.fadeIn();
} else {
primaryNav.fadeOut();
}
});
// listen for browser resize
$( window ).on( 'resize', function() {
// if window is less than 688, just show the menu
if( window.innerWidth < 688 ) {
primaryNav.show();
}
});
});
} )( jQuery );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment