滚动后在引导程序粘性标头上的位置

时间:2019-08-29 16:01:28

标签: jquery header navigation navbar sticky

滚动到页眉的位置时,位置不正确,不会与展开时停留在同一位置。

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.

0 个答案:

没有答案