decentralized-video-chat/public/js/accordion.js

29 lines
851 B
JavaScript
Raw Normal View History

2020-03-31 02:16:08 +08:00
(function () {
"use strict";
const accordionEl = document.getElementsByClassName("accordion-header");
2020-03-24 11:20:28 +08:00
2020-03-31 02:16:08 +08:00
function openAccordion(parent, panel) {
parent.classList.add("is-active");
panel.style.maxHeight = panel.scrollHeight + "px";
2020-03-24 11:20:28 +08:00
}
2020-03-31 02:16:08 +08:00
function closeAccordion(parent, panel) {
parent.classList.remove("is-active");
panel.style.maxHeight = null;
2020-03-24 11:20:28 +08:00
}
if (accordionEl.length > 0) {
for (let i = 0; i < accordionEl.length; i++) {
2020-03-31 02:16:08 +08:00
const el = accordionEl[i];
const parent = el.parentNode;
const panel = el.nextElementSibling;
parent.classList.contains("is-active") && openAccordion(parent, panel);
el.addEventListener("click", function () {
parent.classList.contains("is-active")
? closeAccordion(parent, panel)
: openAccordion(parent, panel);
});
2020-03-24 11:20:28 +08:00
}
}
2020-03-31 02:16:08 +08:00
})();