Creating a Navigation Bar:
<div class="navigation-bar">
<div class="item">Home</div>
<div class="item">About us</div>
<div class="item">Our Services</div>
<div class="item">Contact us</div>
</div>
Styling with CSS:
.navigation-bar {
background: black;
width: 100%;
margin: 0px;
height: 70px;
position: sticky;
}
.f-nav{ /* Fixing the main menu container */
z-index: 9999;
position: fixed;
left: 0;
top: 0;
width: 100%;
}
.item {
float: left;
width: 20%;
height: 100%;
color: white;
text-align: center;
font-family: ‘Lucida Sans Unicode’, ‘Lucida Grande’, sans-serif;
font-size: 26px;
font-weight: 100;
padding-top: 20px;
}
Adding JavaScript functionality:
$("document").ready(function ($) {
var nav = $('.navigation-bar');
$(window).scroll(function () {
if ($(this).scrollTop() > 125) {
nav.addClass("f-nav");
} else {
nav.removeClass("f-nav");
}
});
});
I've implemented this code for a navigation bar, but it's not working as expected. I'm having trouble stopping the navigation bar when it reaches the top of the page. The code seems correct to me, so I'm unsure why it's not functioning properly.