Last active
April 3, 2019 16:15
-
-
Save hunted-down-developer/3b4b4e0f30f17f8bac00df7b810f19c4 to your computer and use it in GitHub Desktop.
Menu Responsivo (vanilla)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//menu | |
let menu = document.querySelector('.navbar-top'); | |
let menuBtn = document.querySelector('.menu-mobile'); | |
//abre o menu clicando no hamburger | |
menuBtn.addEventListener('click', () => { | |
menu.classList.add('navResponsive'); | |
}); | |
//fecha o menu clicando fora da janela | |
document.addEventListener('mouseup', (e) => { | |
if (document.documentElement.clientWidth <= 768) { //verifica o tamanho da tela | |
if(e.target != menu && getComputedStyle(menu, null).display == 'flex'){ | |
menu.classList.add('fading'); | |
setTimeout(() => { | |
menu.classList.remove('fading'); | |
menu.classList.remove('navResponsive'); | |
}, 500); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment