Refactoring menu.js

This commit is contained in:
vimux 2018-10-30 07:25:25 -04:00
parent d6332eff74
commit d0d945b784
No known key found for this signature in database
GPG key ID: 5A34FDC4EE832E34

View file

@ -2,13 +2,10 @@ var toggle = document.getElementById('toggle');
var menu = document.getElementById('menu');
toggle.addEventListener('click', function () {
if (menu.classList.contains('main-nav__list--active')) {
this.setAttribute('aria-expanded', 'false');
this.classList.remove('main-nav__btn--active');
menu.classList.remove('main-nav__list--active');
} else {
menu.classList.add('main-nav__list--active');
this.classList.add('main-nav__btn--active');
this.setAttribute('aria-expanded', 'true');
}
menu.classList.toggle('main-nav__list--active');
this.classList.toggle('main-nav__btn--active');
this.setAttribute(
'aria-expanded',
this.getAttribute('aria-expanded') === 'true' ? 'false' : 'true'
);
});