我正在开发一个网页,需要将其背景颜色从透明变为黑色,并在达到滚动点后添加徽标。 我是javascript的新手,我遇到了一些问题。
目前我一直在改变颜色,但无法弄清楚如何显示图像 我尝试过多种解决方案,但我发现这些解决方案都没有。但
你能帮我一点吗?
HTML:
<body>
<img src="pictures/placeholder1.jpg" id="first_image">
<header>
<img src="pictures/logo.png">
<nav>
<ul>
<li><a href="#">PROIZVODI</a></li>
<li><a href="#">O GALERIJI</a></li>
<li><a href="#">O NAMA</a></li>
<li><a href="#">TIM</a></li>
<li><a href="#">KONTAKT</a></li>
</ul>
</nav>
</header>
<main>
</main>
CSS:
header {
width: 100%;
height: 20%;
font-weight: bold;
position: fixed;
font-size: 14px;
z-index: 100;
background-color: transparent;
}
header img {
float: left;
margin-left: 15%;
height: 80%;
margin-top: 5px;
display: none;
}
#first_image {
width: 100%;
min-width: 1024px;
position: fixed;
top: 0;
left: 0;
z-index: -2;
}
Javascript(jQuery):
$(document).ready(function(){
$(window).scroll(function() {
if ($(document).scrollTop() > 600) {
$("#header").css("background-color", "black");
} else {
$("#header").css("background-color", "transparent");
}
});
});
答案 0 :(得分:0)
$(window).scroll(function() {
if ($(this).scrollTop() > 600) {
$("header").css("background", "black");
$("header img").css('visibility','visible');
} else {
$("header").css("background", "transparent");
$("header img").css('visibility','hidden');
}
});