Last active
September 29, 2016 15:06
-
-
Save jerewall/f5676a0c085c6fa21d9142f5460e12e5 to your computer and use it in GitHub Desktop.
Make any site have a floating navigation, even if Wordpress Admin Bar is present! UPDATED
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) { | |
$('.header').css({ | |
position: 'fixed', | |
top: 0, | |
'z-index': 9999, | |
'max-width': 1200, | |
left: 0, | |
'text-align': 'center', | |
right: 0, | |
'border-radius': 0 | |
}); | |
$('.row-3').css({ | |
'padding-top': '32px' | |
}); | |
if ($('#wpadminbar').length) { | |
$('.header').css('margin-top', '32px'); | |
}; | |
// resets back to what it should be, before the JS change.. | |
} else { | |
$('.header').css({ | |
position: '', | |
top: '', | |
'z-index':'', | |
'border-radius':'' | |
}); | |
$('.row-3').css({ | |
'padding-top': '' | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment