-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
37 lines (35 loc) · 1.19 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
class Accordion {
constructor(element) {
this.element = element;
this.accordionopen(this.element);
window.addEventListener('resize', onResize);
window.addEventListener('orientationchange', onResize);
function onResize() {
let arr = [].slice.call(element.children);
arr.forEach(function (tab) {
if (tab.classList.contains('open')) {
tab.nextElementSibling.classList.add('resize');
tab.nextElementSibling.style.maxHeight = tab.nextElementSibling.scrollHeight + 'px';
}
});
}
}
accordionopen(element) {
element.addEventListener("click", function (e) {
if (e.target.classList.contains('accordion-text')) {
if (!e.target.classList.contains('open')) {
e.target.nextElementSibling.classList.remove('resize');
e.target.classList.add('open');
e.target.nextElementSibling.style.maxHeight = e.target.nextElementSibling.scrollHeight + 'px';
} else {
e.target.nextElementSibling.classList.remove('resize');
e.target.nextElementSibling.style.maxHeight = 0;
e.target.classList.remove('open');
}
}
});
}
}
window.addEventListener("DOMContentLoaded", function () {
new Accordion(document.querySelector('.accordion-container'));
})