-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
45 lines (38 loc) · 1.19 KB
/
app.js
File metadata and controls
45 lines (38 loc) · 1.19 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
;(function () {
const listElements = document.querySelectorAll('.menu_item--show')
const list = document.querySelector('.menu_links')
const menu = document.querySelector('.menu_hamburguer')
const addClick = () => {
listElements.forEach(element => {
element.addEventListener('click', () => {
let subMenu = element.children[1]
let height = 0
element.classList.toggle('menu_item--active')
console.log(menu.clientHeight)
if (subMenu.clientHeight === 0) {
height = subMenu.scrollHeight
}
subMenu.style.height = `${height}px`
})
})
}
window.addEventListener('resize', () => {
if (window.innerWidth > 800) {
deleteStyleHeight()
if (list.classList.contains('menu_links--show'))
list.classList.remove('menu_links--show')
} else {
addClick()
}
})
if (window.innerWidth <= 800) {
addClick()
}
menu.addEventListener('click', () =>
list.classList.toggle('menu_links--show')
)
})()
var botao = document.getElementById('btn')
botao.addEventListener('click', function () {
window.alert('Formulário enviado com sucesso!')
})