generated from emilbaehr/automatic-app-landing-page
-
Notifications
You must be signed in to change notification settings - Fork 10
/
main.js
31 lines (25 loc) · 909 Bytes
/
main.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
28
29
30
31
function initMobileMenu(menuId) {
const menu = document.getElementById(menuId)
const btnId = menu.dataset.controller
const btn = document.getElementById(btnId)
document.addEventListener('click', e => {
// On button
const isTrigger = e.target?.id === btnId
if (isTrigger) {
btn.classList.toggle('sign-close')
menu.classList.toggle('hide-in-phone')
return
}
const isInsideMenu = e.target?.id === menuId || menu.contains(e.target)
if (isInsideMenu) return
// Outside menu
const isMenuHidden = menu.classList.contains('hide-in-phone')
if (isMenuHidden) return
// Outside & Menu shown
btn.classList.remove('sign-close')
menu.classList.add('hide-in-phone')
})
}
window.addEventListener("DOMContentLoaded", _ => {
initMobileMenu("header-menu")
})