You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
916 B
JavaScript

const accordions = document.querySelectorAll(".accordion");
for (const accordion of accordions) {
let expandButton = accordion.querySelector('.more-info input[type="checkbox"]');
let content = accordion.querySelector(".content");
accordion.style.height = expandButton.addEventListener("change", (e) => {
if (e.target.checked) {
content.style.maxHeight = content.scrollHeight + "px";
content.style.marginTop = "24px";
} else {
content.style.marginTop = 0;
content.style.maxHeight = null;
}
});
}
window.addEventListener("resize", (e) => {
for (const accordion of accordions) {
let content = accordion.querySelector(".content");
if (accordion.querySelector('.more-info input[type="checkbox"]').checked) {
content.style.maxHeight = content.scrollHeight + "px";
content.style.marginTop = "24px";
} else {
content.style.marginTop = 0;
content.style.maxHeight = null;
}
}
});