-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
40 lines (38 loc) · 1.64 KB
/
script.js
File metadata and controls
40 lines (38 loc) · 1.64 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
(function () {
// Sticky nav border on scroll
var header = document.querySelector('header');
if (header) window.addEventListener('scroll', function () {
header.classList.toggle('scrolled', window.scrollY > 8);
}, { passive: true });
// FAQ accordion — one open at a time
document.querySelectorAll('.faq-question').forEach(function (btn) {
btn.addEventListener('click', function () {
var item = this.closest('.faq-item');
var isOpen = item.hasAttribute('data-open');
document.querySelectorAll('.faq-item[data-open]').forEach(function (i) {
i.removeAttribute('data-open');
i.querySelector('.faq-question').setAttribute('aria-expanded', 'false');
});
if (!isOpen) { item.setAttribute('data-open', ''); this.setAttribute('aria-expanded', 'true'); }
});
});
// Mobile nav
var hamburger = document.getElementById('hamburger');
var mobileNav = document.getElementById('mobile-nav');
if (hamburger && mobileNav) {
hamburger.addEventListener('click', function () {
var open = mobileNav.classList.toggle('is-open');
this.setAttribute('aria-expanded', open ? 'true' : 'false');
});
document.addEventListener('keydown', function (e) {
if (e.key === 'Escape' && mobileNav.classList.contains('is-open')) {
mobileNav.classList.remove('is-open'); hamburger.setAttribute('aria-expanded', 'false');
}
});
document.addEventListener('click', function (e) {
if (!e.target.closest('header') && mobileNav.classList.contains('is-open')) {
mobileNav.classList.remove('is-open'); hamburger.setAttribute('aria-expanded', 'false');
}
});
}
})();