You can remove the listener, once your class is removed from the body
, that way it won't trigger any more when you scroll.
Here's the code:
var removeMenuClass = function() {
document.body.classList.remove('mobile-menu-open');
// remove the scroll listener
window.removeEventListener('scroll', removeMenuClass, false);
}
// add the scroll listener
window.addEventListener('scroll', removeMenuClass, false);
If needed (let's say when your "mobile-menu" re-opens), you can re-attach the eventListener the same way.