向下滚动到现场后,如何使标头颜色更改



这是我在这里的第一个问题。我在将标头滚动在主页上后更改颜色的问题有问题。我搜索了Stackoverflow存档,并找到了此线程,但不知道如何在我的网站上工作。有人可以告诉我如何整合这个吗?谢谢

很简单,只需使用此JavaScript:

window.addEventListener("scroll","myFunction");
function myFunction() {
  var myscroll = 200; // Replace this value with the height you want to scroll
                      // to change the header background
  var myheader = ; // your header selector here
  if (document.body.scrollTop > myscroll || document.documentElement.scrollTop > myscroll) {
    myheader.style.backgroundColor = "#40A824"; // Replace this with the
                                                // color you want after scrolling
  }
}

最新更新