-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
27 lines (16 loc) · 878 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//colocando id do botão dentro da variavel
const btnMobile = document.getElementById('btn-mobile');
function toggleMenu(event) {
if (event.type === 'touchstart') event.preventDefault();
const nav = document.getElementById('nav');
nav.classList.toggle('active');
const active = nav.classList.contains('active');
event.currentTarget.setAttribute('aria-expanded' , active);
if (active) {
event.currentTarget.setAttribute('aria-label' , 'Fechar Menu');
} else {
event.currentTarget.setAttribute('aria-label' , 'Abrir Menu');
}
}
btnMobile.addEventListener('click' , toggleMenu);
btnMobile.addEventListener('touchstart' , toggleMenu);