-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
64 lines (47 loc) · 1.56 KB
/
app.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const button = document.querySelector('.icon')
const containerItem = document.querySelector('.back')
const internalHightLiContainer = () => {
const lis = [...document.querySelector('.back').children]
const internalSizeLi = lis[0].offsetHeight
const totalAmountLis = lis.length
const heightLiContainer = totalAmountLis * internalSizeLi
return heightLiContainer
}
const createAnimation = (inicialSize, finalSize) => {
const keyFrame = [
{ height: `${inicialSize}px` },
{ height: `${finalSize}px` },
]
const configAnimation = {
duration: 200,
fill: 'forwards'
}
containerItem.animate(keyFrame, configAnimation)
}
const addRotateToButtom = () => {
button.classList.add('rotateIcon')
}
const removeRotateToButtom = () => {
button.classList.remove('rotateIcon')
}
const addEventsOnDropDown = () => {
if (button.classList.contains('rotateIcon')) {
removeRotateToButtom()
createAnimation(0, internalHightLiContainer())
} else {
createAnimation(internalHightLiContainer(), 0)
addRotateToButtom()
}
}
const closeDropAndRotateIcon = () => {
createAnimation(internalHightLiContainer(), 0)
addRotateToButtom()
}
const showNameSelectedItem = (e) => {
const container = document.querySelector(".textContainer")
const internalTextLi = e.target.textContent
container.textContent = internalTextLi
closeDropAndRotateIcon()
}
button.addEventListener('click', addEventsOnDropDown)
containerItem.addEventListener('click', (e) => showNameSelectedItem(e))