this is my javaskript and i think the problem is here?
it jump so how to fix it.
it can not reach the bottum
window.onscroll = function() {
myFunction();
};
var navbar = document.getElementById("navbar");
var placeholder = document.getElementById("navbar-placeholder");
var sticky = navbar.offsetTop - 10;
function myFunction() {
if (window.scrollY >= sticky) {
navbar.classList.add("sticky");
placeholder.style.height = navbar.offsetHeight + "px"; // Set placeholder height
} else {
navbar.classList.remove("sticky");
placeholder.style.height = "0"; // Reset placeholder height
}
}
2
Answers
here is my css:
how about just css and the position sticky attribute. https://blog.hubspot.com/website/css-position-sticky