Добавил хуйню, шоб FAQ раскрывалось нормально на мобилках

This commit is contained in:
Alexander Zaytsev 2026-06-02 22:26:47 +03:00 committed by GitHub
parent 2a04f1cfaa
commit e1af430022
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -599,21 +599,38 @@ window.addEventListener('scroll', () => {
// ---- FAQ: аккордеон ---- // ---- 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 => { document.querySelectorAll('.faq-question').forEach(btn => {
btn.addEventListener('click', () => { btn.addEventListener('click', () => {
const expanded = btn.getAttribute('aria-expanded') === 'true'; const expanded = btn.getAttribute('aria-expanded') === 'true';
const answer = btn.nextElementSibling; const answer = btn.nextElementSibling;
// Закрыть все остальные
document.querySelectorAll('.faq-question').forEach(b => { document.querySelectorAll('.faq-question').forEach(b => {
b.setAttribute('aria-expanded', 'false'); b.setAttribute('aria-expanded', 'false');
b.nextElementSibling.classList.remove('open'); setFaqAnswerHeight(b.nextElementSibling, false);
}); });
// Переключить текущий
if (!expanded) { if (!expanded) {
btn.setAttribute('aria-expanded', 'true'); 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';
} }
}); });
}); });