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'); var menu = document.getElementById('menu');
toggle.addEventListener('click', function () { toggle.addEventListener('click', function () {
if (menu.classList.contains('main-nav__list--active')) { menu.classList.toggle('main-nav__list--active');
this.setAttribute('aria-expanded', 'false'); this.classList.toggle('main-nav__btn--active');
this.classList.remove('main-nav__btn--active'); this.setAttribute(
menu.classList.remove('main-nav__list--active'); 'aria-expanded',
} else { this.getAttribute('aria-expanded') === 'true' ? 'false' : 'true'
menu.classList.add('main-nav__list--active'); );
this.classList.add('main-nav__btn--active');
this.setAttribute('aria-expanded', 'true');
}
}); });