I have a simple script that basically waits till my navigation has scrolled off the screen, resizes it slightly then it animates in from the top of the screen and remains fixed till i scroll back up.
When you scroll past the menu it animates back in, but then repeats this animation every time I finish scrolling. I have tried adding the animation outside of the scroll function but then it doesn't animate at all.
Have i missed something simple?
var Header = $('#header'),
Navbar = $('.navbar'),
links = $(".navbar ul.nav > li > a"),
HeaderH = Header.height(),
NavbarH = Navbar.height();
$(window).scroll(function () {
if ($(this).scrollTop() > (HeaderH + NavbarH)) {
Navbar.addClass('navbar-fixed-top')
links.css('padding', '10px 20px 10px 20px');
Header.css('margin-bottom', '64px');
Navbar.css('top', '-64px').animate({'top' : '0'}, 1000);
}
else{
Navbar.removeClass('navbar-fixed-top')
links.css('padding', '20px');
}
});
The site is built on joomla with bootstrap, hence the navbar-fixed-top style classes.