Spaces:
Running
Running
// Programs Page JavaScript | |
document.addEventListener('DOMContentLoaded', function() { | |
// FAQ Accordion | |
const faqQuestions = document.querySelectorAll('.faq-question'); | |
faqQuestions.forEach(question => { | |
question.addEventListener('click', function() { | |
const answer = this.nextElementSibling; | |
const isExpanded = this.getAttribute('aria-expanded') === 'true'; | |
// Close all other answers | |
document.querySelectorAll('.faq-answer').forEach(item => { | |
if (item !== answer) { | |
item.classList.remove('active'); | |
} | |
}); | |
document.querySelectorAll('.faq-question').forEach(item => { | |
if (item !== this) { | |
item.setAttribute('aria-expanded', 'false'); | |
} | |
}); | |
// Toggle current answer | |
if (isExpanded) { | |
answer.classList.remove('active'); | |
this.setAttribute('aria-expanded', 'false'); | |
} else { | |
answer.classList.add('active'); | |
this.setAttribute('aria-expanded', 'true'); | |
} | |
}); | |
}); | |
// Initialize the first FAQ item as open | |
if (faqQuestions.length > 0) { | |
faqQuestions[0].setAttribute('aria-expanded', 'true'); | |
faqQuestions[0].nextElementSibling.classList.add('active'); | |
} | |
// Animate elements when they come into view | |
const animateOnScroll = function() { | |
const elements = document.querySelectorAll('.program-card, .curriculum-item, .testimonial-card'); | |
elements.forEach(element => { | |
const elementPosition = element.getBoundingClientRect().top; | |
const windowHeight = window.innerHeight; | |
if (elementPosition < windowHeight - 100) { | |
element.classList.add('fade-in'); | |
} | |
}); | |
}; | |
// Run once on page load | |
animateOnScroll(); | |
// Run on scroll | |
window.addEventListener('scroll', animateOnScroll); | |
}); |