Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save nextab/454e21bb503f2e181a374e54d286277b to your computer and use it in GitHub Desktop.

Select an option

Save nextab/454e21bb503f2e181a374e54d286277b to your computer and use it in GitHub Desktop.
//#region Add body class when mobile nav is opened
const mob_nav = document.getElementsByClassName('mobile_nav')[0];
console.log(mob_nav);
// Toggle mobile nav on click
mob_nav.addEventListener('click', function() {
document.getElementsByTagName('body')[0].classList.toggle('mobile_nav-opened');
});
// Close mobile nav with ESC key
document.addEventListener('keydown', function(event) {
if (event.key === 'Escape') {
if (mob_nav.classList.contains('opened')) {
let mobile_nav_button = mob_nav.getElementsByClassName('mobile_menu_bar_toggle')[0];
mobile_nav_button.click();
}
}
});
//#endregion Add body class when mobile nav is opened
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment