I've been working on creating a website for my business but I'm facing a challenge.
My goal is to have a fixed navigation bar that stays in place as people scroll down the page,
similar to what you can see on this website: (where the navigation bar remains fixed while scrolling)
I am using jQuery 1.8.3.min.js and the following code:
$(window).bind('scroll', function() {
if ($(window).scrollTop() > 50) {
$('.nav').addClass('absolute');
}
else {
$('.nav').removeClass('fixed');
}
});
Here is how the CSS looks:
header .nav{
top: 55px;
padding: 0;
min-height: 0;
font-family: 'Lato', sans-serif;
text-transform: uppercase;
font-size: 12px;
letter-spacing: 0.5px;
line-height: 3px;
width: 100%;
position: absolute;
z-index: 999;
}
.fixed{
position: fixed;
top: 0; }
However, I am not able to get it to work correctly. Does anyone have any suggestions on how to fix it?
Thank you!! :D
p.s. Please excuse any mistakes in my English.