I've been attempting to change the background color of my navbar on scroll, but I keep encountering this error: 'Uncaught TypeError: Cannot read property 'add' of undefined'. Can someone please help me identify and fix the issue? Here is the CSS class that I'm trying to remove after it scrolls over the first page:
.navbar {
background: transparent !important;
z-index: 10;
border-bottom: 1px solid rgba(255, 255, 255, 0.3);
position: fixed;
width: 100%;
}
And here is the CSS class that I'm attempting to add after scrolling into the second page or beyond:
.navbar-active{
position: fixed;
background-color: rgba(0, 0, 0, .692) !important;
box-shadow: 0 3px 1rem rgba(0, 0, 0, .1);
border-bottom: 1px solid rgba(255, 255, 255, 0.3);
}
Lastly, here is my JavaScript code to swap out the class lists:
const navbar = document.getElementsByClassName('navbar');
window.onscroll = function(){
const top = window.scrollY;
if(top >= 693){
navbar.classList.add('.navbar-active');
} else {
navbar.classList.remove('.navbar-active');
}
}