I was able to make the navbar stick to the top of the screen when the user scrolls past it, but it causes a bump, breaking the flow. How does one fix this?
// * NAVIGATION BAR STYLING
.nav__container {
background: colors(col-light-black);
height: 5rem;
border-bottom: 3px solid colors(col-orange);
display: flex;
justify-content: start;
align-items: center;
}
.links-wrapper {
list-style: none;
text-transform: uppercase;
display: flex;
margin-left: 2rem;
}
a {
text-decoration: none;
}
.page-link {
padding: 0;
margin: 0 2.5rem;
transition: 0.5s;
@include responsive(lg) {
margin: 0 1.8rem;
}
@include responsive(md) {
//TODO HAMBURGER MENU
}
&:hover {
color: colors(col-primary-blue);
cursor: pointer;
}
&:active {
color: colors(col-dark-blue);
}
}
.sticky {
position: fixed;
top: 0;
width: 100%;
}
.sticky + .content {
padding-top: 6rem;
}
<nav class="nav__container">
<ul class="links-wrapper">
<li class="page-link li" onclick="redirect('#header')">Home</li>
<li class="page-link li" onclick="redirect('#about')">About</li>
<li class="page-link li" onclick="redirect('#skills')">Skills</li>
<li class="page-link li" onclick="redirect('#projects')">Projects</li>
<li class="page-link li" onclick="redirect('#contact')">Contact</li>
</ul<
</nav>
// * STICKY NAVBAR
window.onscroll = function() {
stickyAdd();
};
const navbar = document.querySelector(".nav__container");
let sticky = navbar.offsetTop;
function stickyAdd() {
if (window.pageYOffset - 50 >= sticky) {
navbar.classList.add("sticky");
} else {
navbar.classList.remove("sticky");
}
}