-
-
Save rfmeier/c421a5bf60ec886a38a1 to your computer and use it in GitHub Desktop.
Show menu based on scroll position.
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
( 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