title: How Do I Make Transparent Navbar Have Background Color After Scroll?
body: <p>I want to give my navbar the effect of being transparent initially, but upon scrolling is given a black background color. I understand that Javascript is best suited for the job, but I have tried <code>window.addEventListener</code> and have remained unsuccessful. Any tips at all are greatly appreciated.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>&lt;script&gt;
          window.addEventListener( 'scroll', function () {
              let nav = document.querySelector('nav');
  
              nav.classList.toggle('scrolling-active');
          });
      &lt;/script&gt;</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>#header {
    height: 100vh;
  }
  
  #header nav {
    display: flex;
    background-color: transparent;
    justify-content: space-between;
    position: fixed;
    width: 100vw;
  }
  
  
  #header nav .name {
    display: flex;
    width: fit-content;
    color: white;
    padding-left: 30px;
    align-items: center;
    font-size: 30px;
  }
  
  #header nav .name span {
    color: rgb(182, 18, 18);
  }
  
  #header nav ul {
    display: flex;
    list-style: none;
    width: fit-content;
  }
  
  #header nav ul li {
    padding: 30px;
  }
  
  #header nav ul li a {
    text-decoration: none;
    font-size: 25px;
    color: white;
    font-family: "Yanone Kaffeesatz", sans-serif;
  }
  
  .scrolling-active {
    background-color: black;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;header id="header"&gt;
          &lt;section class="hero"&gt;
              &lt;nav class="nav"&gt;
                  &lt;div class="name"&gt;&lt;h1&gt;&lt;span&gt;D&lt;/span&gt;ave &lt;span&gt;A&lt;/span&gt;nthony&lt;/h1&gt;&lt;/div&gt;
                  &lt;ul&gt;
                      &lt;li&gt;&lt;a href="#"&gt;Home&lt;/a&gt;&lt;/li&gt;
                      &lt;li&gt;&lt;a href="#"&gt;About&lt;/a&gt;&lt;/li&gt;
                      &lt;li&gt;&lt;a href="#"&gt;Recent Posts&lt;/a&gt;&lt;/li&gt;
                  &lt;/ul&gt;
              &lt;/nav&gt;</code></pre>
  </div>
  </div>
  </p>