Last active
February 16, 2018 18:46
-
-
Save jerewall/5009a6bf53ad545d65275d712e52e9ad to your computer and use it in GitHub Desktop.
Sticky Nav V3 - no jumps on short pages and responsive
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
/* Sticky navigation bar - Make the navigation area float after scrolling past it */ | |
var aboveHeight = $('#primary-navigation').offset().top; | |
jQuery(window).scroll(function () { | |
if ($(window).scrollTop() > aboveHeight && $(window).width() > 780) { | |
$('.header').css({ | |
'position': 'fixed', | |
'top': -90, | |
'left': 0, | |
'right': 0, | |
'z-index': 9999, | |
'max-width': 1200, | |
'text-align': 'center', | |
'border-radius': 0 | |
}); | |
$('.top').css({ | |
'padding-bottom': ($('.header').outerHeight(true) + 90) | |
}); | |
if ($('#wpadminbar').length) { | |
$('.header').css('margin-top', '32px'); | |
}; | |
} else { | |
// resets back to what it should be, before the JS change.. | |
$('.header').css({ | |
'position': '', | |
'top': '', | |
'z-index': '', | |
'border-radius': '', | |
'max-width': '' | |
}); | |
$('.top').css({ | |
'padding-bottom': 0 | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment