I'm using jQuery to change the CSS elements of the Bootstrap navbar after scrolling. The issue I have is that if you load the page anywhere after the top of the page, the menu won't get smaller until you scroll down - with the below code:
var a = $(".nav").offset().top;
$(document).scroll(function(){
if($(this).scrollTop() > a)
{
$('.navbar-fixed-top').css({"background":"#fff"});
$('.navbar-fixed-top').css({"transition":"0.5s"});
$('.navbar-fixed-top li a').css({"padding-top":"20px"});
$('.navbar-fixed-top li a').css({"padding-bottom":"20px"});
} else {
$('.navbar-fixed-top').css({"background":"transparent"});
$('.navbar-fixed-top').css({"transition":"0.5s"});
$('.navbar-fixed-top li a').css({"padding-top":"40px"});
$('.navbar-fixed-top li a').css({"padding-bottom":"40px"});
}
});
I've been trying to change it so that if it's not at the top of the page, it'll execute the scrollTop code, but with no luck.