-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFaq.js
More file actions
63 lines (52 loc) · 2.24 KB
/
Faq.js
File metadata and controls
63 lines (52 loc) · 2.24 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
53
54
55
56
57
58
59
60
61
62
63
const hamburger = document.getElementById('hamburger');
const dropdownMenu = document.getElementById('dropdown-menu');
const toggleMenu = () => {
if (dropdownMenu.style.display === 'block') {
dropdownMenu.style.display = 'none';
} else {
dropdownMenu.style.display = 'block';
}
};
const checkWidth = () => {
if (window.innerWidth > 768) {
dropdownMenu.style.display = 'none';
}
};
hamburger.addEventListener('click', toggleMenu);
window.addEventListener('resize', checkWidth);
// Close the dropdown if the user clicks outside of it
window.addEventListener('click', (event) => {
if (!event.target.matches('#hamburger')) {
if (dropdownMenu.style.display === 'block') {
dropdownMenu.style.display = 'none';
}
}
});
/*
document.querySelectorAll('.faq h3').forEach(item => {
item.addEventListener('click', () => {
const content = item.nextElementSibling;
const sign = item.querySelector('.dropdown-sign');
const isOpen = content.style.display === 'block';
document.querySelectorAll('.faq p').forEach(p => p.style.display = 'none');
document.querySelectorAll('.dropdown-sign').forEach(s => s.textContent = '>');
content.style.display = isOpen ? 'none' : 'block';
sign.textContent = isOpen ? '>' : 'v';
});
});
*/
document.querySelectorAll('.faq h3').forEach(item => {
item.addEventListener('click', () => {
const content = item.nextElementSibling;
const img = item.querySelector('.dropdown-sign img');
const isOpen = content.style.display === 'block';
// Close all other content sections
document.querySelectorAll('.faq p').forEach(p => p.style.display = 'none');
// Reset all dropdown images to the closed state
document.querySelectorAll('.dropdown-sign img').forEach(i => i.src = 'images/icons8-chevron-right-50.png');
// Toggle the current content section
content.style.display = isOpen ? 'none' : 'block';
// Switch the image source based on the dropdown state
img.src = isOpen ? 'images/icons8-chevron-right-50.png' : 'images/icons8-chevron-down-50.png';
});
});