Skip to content

Instantly share code, notes, and snippets.

@seothemes
Created August 3, 2017 03:51
Show Gist options
  • Save seothemes/213ed908e8978fa22665d6c13344898c to your computer and use it in GitHub Desktop.
Save seothemes/213ed908e8978fa22665d6c13344898c to your computer and use it in GitHub Desktop.
Sticky Primary Nav for Genesis Sample theme
( function ($) {
// Make nav fixed.
$( document ).ready(function() {
$( '.nav-primary' ).css( {
'position': 'absolute',
'left': '0',
'width': '100%',
'z-index': '99'
} ).delay( 1 ).css( 'top', $( '.site-header' ).height() );
$( '.site-inner' ).css( 'margin-top', $( '.nav-primary').height() );
});
// Get distance from nav to top.
var distance = $( '.site-header' ).outerHeight();
// If distance less than 0.
$( window ).scroll( function() {
if ( $( window).scrollTop() >= distance ) {
$( '.nav-primary' ).css( {
'top': '0',
'position': 'fixed'
} );
}
else {
$( '.nav-primary' ).css( {
'top': $( '.site-header' ).height(),
'position': 'absolute'
} );
}
});
} )( jQuery );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment