Close mobile menu with esc key.
This commit is contained in:
parent
f856eb17dc
commit
608bf2538d
1 changed files with 9 additions and 0 deletions
|
|
@ -15,14 +15,23 @@
|
|||
nav.classList.add('js-nav-open');
|
||||
sheet.setAttribute('aria-hidden', 'false');
|
||||
toggle.setAttribute('aria-expanded', 'true');
|
||||
document.body.addEventListener('keydown', closeonesc);
|
||||
}
|
||||
|
||||
function navclose() {
|
||||
nav.classList.remove('js-nav-open');
|
||||
sheet.setAttribute('aria-hidden', 'true');
|
||||
toggle.setAttribute('aria-expanded', 'false');
|
||||
document.body.removeEventListener('keydown', closeonesc);
|
||||
}
|
||||
|
||||
// Close the nav sheet with "esc" key.
|
||||
function closeonesc(e) {
|
||||
if (e.key === 'Escape') {
|
||||
navclose();
|
||||
}
|
||||
};
|
||||
|
||||
// Toggle the mobile nav sheet.
|
||||
const toggles = document.querySelectorAll('.mobile-nav__cover, .mobile-nav__toggle');
|
||||
toggles.forEach(function (toggle) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue