-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
31 lines (26 loc) · 1.14 KB
/
Copy pathscript.js
File metadata and controls
31 lines (26 loc) · 1.14 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
// Load the global chromatic layer after the base stylesheet on every page.
const colorPass = document.createElement('link');
colorPass.rel = 'stylesheet';
colorPass.href = new URL('color-pass.css', document.currentScript?.src || document.baseURI).href;
document.head.appendChild(colorPass);
const header = document.querySelector('[data-header]');
const menuButton = document.querySelector('[data-menu-button]');
const nav = document.querySelector('[data-nav]');
const year = document.querySelector('[data-year]');
if (year) year.textContent = new Date().getFullYear();
const updateHeader = () => {
header?.classList.toggle('is-scrolled', window.scrollY > 10);
};
updateHeader();
window.addEventListener('scroll', updateHeader, { passive: true });
menuButton?.addEventListener('click', () => {
const open = menuButton.getAttribute('aria-expanded') === 'true';
menuButton.setAttribute('aria-expanded', String(!open));
nav?.classList.toggle('is-open', !open);
});
nav?.querySelectorAll('a').forEach((link) => {
link.addEventListener('click', () => {
menuButton?.setAttribute('aria-expanded', 'false');
nav?.classList.remove('is-open');
});
});