如何在站点中向下滚动后进行标题颜色更改?

时间:2016-12-14 15:40:25

标签: jquery html css

这是我的第一个问题。在主页中向下滚动后,我有一个问题是让标题改变颜色。我搜索了Stackoverflow存档,发现了这个thread,但不知道如何使这个工作在my site上。有人可以告诉我如何整合这个?感谢

1 个答案:

答案 0 :(得分:0)

这很简单,只需使用此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
  }
}