My goal is, when user pass my first section(#video-section)
, I want to close my side menu.
This is my code:
// When the user scrolls the page, execute myFunction
window.onscroll = function() {
var video = document.getElementById("video-section");
var menubar = document.getElementsByClassName("menubar");
var drawer = document.getElementsByClassName("drawer");
var videoheight = video.offsetHeight;
console.log("Scroll amount:" + window.pageYOffset);
console.log("Video section amount:" + videoheight)
if (window.pageYOffset == videoheight) {
console.log("Passed");
menubar.classList.remove("open");
}
};
I get the following error message at the classList.remove()
function call:
Uncaught TypeError: Cannot read property 'remove' of undefined at window.onscroll