在以下代码中,标题颜色是透明的。我想把它的颜色改成"#FFF"当我向下滚动页面时 。请指导我如何编写相关的js代码。
另外,可以通过普通的CSS进行吗?
div {
height: 1000px;
width: 100%;
}
#home {
background-color: red;
}
header {
background-color: transparent;
color: ffffff;
height: 100px;
position: fixed;
width: 100%;
top: 0;
z-index: 100;
}

<header>Top Navigation</header>
<div id="home" class="sect"></div>
&#13;
答案 0 :(得分:1)
Pen试试这个。它应该对你有所帮助。你应该用jquery或普通的javascript
来做$(document).ready(function() {
$(window).scroll(function () {
//if you hard code, then use console
//.log to determine when you want the
//nav bar to stick.
console.log($(window).scrollTop())
if ($(window).scrollTop() > 10) {
$('header').css('background-color','#FFF');
}
if ($(window).scrollTop() < 10) {
$('header').css('background-color','transparent');
}
});
});
答案 1 :(得分:0)
您是否尝试使用background-color:rgba(0,0,0,0);
?