So here's what I'm trying to do, I have a sticky navigation at the top of a page with a background that's transparent. But when the user scrolls down and the content is underneath the navigation, I want to change the background of the navigation so it is NOT transparent. Now I've already achieved this, but my question is: is it possible when the user scrolls back to the top of the page for the navigation background to become transparent again?
For example: user loads page, navigation is transparent, user scrolls down, navigation background turns NON transparent, then user scrolls back to top of page. Is it possible to make the navigation background become transparent again? Also I am trying to achieve this without using jquery! So answer only in raw javascript please!
___JS___
window.onscroll = function nav_bg(){
var header = document.getElementById("header");
header.setAttribute('style','background-color:rgba(0,0,0,1);')
}
___CSS___
#header{background-color:rgba(0,0,0,.4);}
This is my current code, but when the user scrolls back to the top, the background stays non-transparent.