diff --git a/services/burka_wed/script.js b/services/burka_wed/script.js index 929b30e..0a820f2 100644 --- a/services/burka_wed/script.js +++ b/services/burka_wed/script.js @@ -599,21 +599,38 @@ window.addEventListener('scroll', () => { // ---- FAQ: аккордеон ---- +function setFaqAnswerHeight(answer, open) { + if (open) { + answer.classList.add('open'); + answer.style.maxHeight = answer.scrollHeight + 'px'; + } else { + answer.classList.remove('open'); + answer.style.maxHeight = '0px'; + } +} + document.querySelectorAll('.faq-question').forEach(btn => { btn.addEventListener('click', () => { const expanded = btn.getAttribute('aria-expanded') === 'true'; const answer = btn.nextElementSibling; - // Закрыть все остальные document.querySelectorAll('.faq-question').forEach(b => { b.setAttribute('aria-expanded', 'false'); - b.nextElementSibling.classList.remove('open'); + setFaqAnswerHeight(b.nextElementSibling, false); }); - // Переключить текущий if (!expanded) { btn.setAttribute('aria-expanded', 'true'); - answer.classList.add('open'); + setFaqAnswerHeight(answer, true); + } + }); +}); + +window.addEventListener('resize', () => { + document.querySelectorAll('.faq-question[aria-expanded="true"]').forEach(btn => { + const answer = btn.nextElementSibling; + if (answer.classList.contains('open')) { + answer.style.maxHeight = answer.scrollHeight + 'px'; } }); });