滚动到页眉的位置时,位置不正确,不会与展开时停留在同一位置。
I have used a script which works on window scroll which adds a class to the navbar once the windowpageYoffset is less than the offsetTop. I have created a similar JSFiddle to replicate the issue I am facing https://jsfiddle.net/Bradplaydon/g89wkj0h/28/
window.onscroll = function() {myFunction()};
var header = document.getElementById("myHeader");
var sticky = header.offsetTop;
function myFunction() {
if (window.pageYOffset > sticky) {
header.classList.add("sticky");
} else {
header.classList.remove("sticky");
}
}
Expected headers position to stay the same after scrolling.