I recently used pure JavaScript to change the color of my navbar after scrolling. Surprisingly, it worked perfectly fine on Google Chrome without any issues. However, when I decided to test it on Firefox, the feature stopped working altogether.
Can anyone provide me with some advice on how to fix this problem? Thank you in advance.
var myNav = document.getElementById("nav");
window.onscroll = function () {
"use strict";
if (document.body.scrollTop >= 280) {
myNav.classList.add("scroll");
} else {
myNav.classList.remove("scroll");
}
};
body {
margin:0;
padding:0;
height:4000px;
}
.nav {
position:fixed;
width:100%;
height:60px;
background-color:#111;
transition:all .5s ease-in-out;
}
.scroll {
background-color:transparent;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="nav" class="nav"></div>