I have a hamburger button that sticks to the top right corner of the page as you scroll down the page. When clicked, the hamburger button displays a nav menu. However, if I scroll up on the page the hamburger button functionality does not work. In my code, the hamburger button is named "menuBtn" and the sticky class that is added in the code just makes the position of the button fixed. I have attached my JavaScript code because I believe this is the problem.
const hamburgerMenu = document.querySelector('.hamburger__anchors--bin');
const menuBtn = document.querySelector('.menu-btn');
//sticky hamburger btn
window.onscroll = function() {
if(window.pageYOffset >= menuBtn.offsetTop) {
menuBtn.classList.add('sticky')
hamburgerMenu.classList.toggle('stickytwo');
} else {
menuBtn.classList.remove('sticky')
}
}