Currently, I am designing a website where I need the background color to transition from transparent to black and display a logo once the user scrolls down to a certain point. I am a beginner in javascript and I am facing some difficulties with this task.
For reference, here is an example:
Although I have managed to change the background color, I am struggling to show the image as well. I have tried various solutions found online, but none seem to work for me.
Could someone please assist me with this issue?
HTML:
<body>
<img src="pictures/placeholder1.jpg" id="first_image">
<header>
<img src="pictures/logo.png">
<nav>
<ul>
<li><a href="#">PRODUCTS</a></li>
<li><a href="#">ABOUT US</a></li>
<li><a href="#">OUR TEAM</a></li>
<li><a href="#">CONTACT</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");
}
});
});