-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
40 lines (33 loc) · 1.39 KB
/
Copy pathscript.js
File metadata and controls
40 lines (33 loc) · 1.39 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
const header = document.querySelector('[data-header]');
const menuButton = document.querySelector('.menu-button');
const navigation = document.querySelector('.site-nav');
const navLinks = document.querySelectorAll('.site-nav a');
const year = document.querySelector('[data-year]');
year.textContent = new Date().getFullYear();
const closeMenu = () => {
menuButton.setAttribute('aria-expanded', 'false');
navigation.classList.remove('is-open');
document.body.style.overflow = '';
};
menuButton.addEventListener('click', () => {
const isOpen = menuButton.getAttribute('aria-expanded') === 'true';
menuButton.setAttribute('aria-expanded', String(!isOpen));
navigation.classList.toggle('is-open', !isOpen);
document.body.style.overflow = isOpen ? '' : 'hidden';
});
navLinks.forEach((link) => link.addEventListener('click', closeMenu));
window.addEventListener('resize', () => {
if (window.innerWidth > 900) closeMenu();
});
window.addEventListener('scroll', () => {
header.classList.toggle('is-scrolled', window.scrollY > 24);
}, { passive: true });
const revealObserver = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add('is-visible');
revealObserver.unobserve(entry.target);
}
});
}, { threshold: 0.12 });
document.querySelectorAll('.reveal').forEach((element) => revealObserver.observe(element));