title: Ho to make a navbar that fades in when the page is scrolled
body: <p>I made a navigation bar with a background that changes color from transparent to translucent black when the user scrolls down. My problem is I can't get it to change back to transparent when the user scrolls to the top of the page
  here what i have so far</p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;nav id="mynav" style="transition: 1.4s ease-in" position:fixed;&gt; &lt;div class="collapse navbar-collapse" id="collapsibleNavbar"&gt;
  &lt;ul class="navbar-nav"&gt;
    &lt;li class="nav-item"&gt;
      &lt;a class="nav-link" href="Courses.html"&gt;Home&lt;/a&gt;
    &lt;/li&gt;
    &lt;li class="nav-item"&gt;
      &lt;a class="nav-link" href="Log In"&gt;Videos&lt;/a&gt;
    &lt;/li&gt;
    &lt;li class="nav-item"&gt;
      &lt;a class="nav-link" href="#"&gt;Images&lt;/a&gt;
    &lt;/li&gt;    
  &lt;/ul&gt;&lt;/nav&gt;
  </code></pre>
  
  <p>JS:</p>
  
  <pre><code>    window.onscroll = navfade;
  function navfade(){
      var nbar = document.getElementById("mynav");
      if(nbar.scrollTop &lt; 5){
          nbar.style.background = "rgba(10,10,20,0.45)";
      }else {
          nbar.style.background = "transparent";
      }
  }
  </code></pre>