-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
52 lines (47 loc) · 1.78 KB
/
script.js
File metadata and controls
52 lines (47 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
document.addEventListener('DOMContentLoaded', () => {
const hamburger = document.querySelector('.hamburger');
const navLinks = document.querySelector('.nav-links');
const allNavLinks = document.querySelectorAll('.nav-links li a');
const overlay = document.querySelector('.overlay');
const toggleNav = () => {
navLinks.classList.toggle('active');
hamburger.classList.toggle('active');
overlay.classList.toggle('active');
const isExpanded = hamburger.getAttribute('aria-expanded') === 'true';
hamburger.setAttribute('aria-expanded', !isExpanded);
};
if (hamburger && navLinks) {
hamburger.addEventListener('click', toggleNav);
}
allNavLinks.forEach(link => {
link.addEventListener('click', () => {
if (navLinks.classList.contains('active')) {
toggleNav();
}
});
});
if (overlay) {
overlay.addEventListener('click', () => {
if (navLinks.classList.contains('active')) {
toggleNav();
}
});
}
// ================== FAQ FUNCTIONALITY ==================
const faqQuestions = document.querySelectorAll('.faq-question');
faqQuestions.forEach(question => {
question.addEventListener('click', () => {
const faqItem = question.parentElement;
const isActive = faqItem.classList.contains('active');
// Close all other FAQ items
faqQuestions.forEach(otherQuestion => {
const otherItem = otherQuestion.parentElement;
otherItem.classList.remove('active');
});
// Toggle current FAQ item
if (!isActive) {
faqItem.classList.add('active');
}
});
});
});