I'm working on this site as a fun side project, but I've hit a roadblock. The sticky nav bar I implemented jumps when the user scrolls down far enough. Despite reading through other discussions, I can't seem to figure out the solution.
I suspect it might be related to padding, but my JavaScript skills are not the best, so there may be errors in that area as well.
This is the JavaScript code I'm using:
var header = document.getElementById("header");
var navbar = document.getElementById("navbar");
var navbarHeight = navbar.offsetHeight;
var headerHeight = header.offsetHeight;
header.style.height = screen.height - navbarHeight;
function initJake() {
if (window.pageYOffset > headerHeight) {
navbar.style.position = "fixed";
navbar.style.top = "0";
} else {
navbar.style.position = "relative";
}
}
window.onscroll = function() {
initJake()
};
You can view the full example on jsFiddle here: https://jsfiddle.net/jihlenfeldt/435ugdyf/2/
I'm looking for a way to smoothly transition from absolute to fixed positioning without covering text lines. Any advice would be greatly appreciated, as this issue has been quite frustrating for me.