-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (35 loc) · 1.27 KB
/
index.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
let minusToggleBtns = document.querySelectorAll(".accordion-tile-heading-minus-icon");
let plusToggleBtns = document.querySelectorAll(".accordion-tile-heading-plus-icon");
let accordionTiles = document.querySelectorAll(".accordion-tile")
showFirstTile()
function showFirstTile() {
let firstTile = accordionTiles[0]
firstTile.dataset.status = "visible"
let contentWrapper = firstTile.children[1]
showTileContent(contentWrapper)
}
minusToggleBtns.forEach((el) => {
el.addEventListener('click', toggleTiles)
})
plusToggleBtns.forEach((el) => {
el.addEventListener('click', toggleTiles)
})
function toggleTiles(event) {
accordionTiles.forEach((el)=>{
el.dataset.status = "hidden"
let contentWrapper = el.children[1]
hideTileContent(contentWrapper)
})
if(event.currentTarget.classList.contains("accordion-tile-heading-minus-icon"))
return
let parentTile = event.currentTarget.parentElement.parentElement
parentTile.dataset.status = "visible"
let contentWrapper = parentTile.children[1]
showTileContent(contentWrapper)
}
function hideTileContent(tileWrapper) {
tileWrapper.style.maxHeight = "0px"
}
function showTileContent(tileWrapper) {
tileWrapper.style.maxHeight = tileWrapper.scrollHeight + "px"
}