-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
18 lines (15 loc) · 804 Bytes
/
Copy pathscript.js
File metadata and controls
18 lines (15 loc) · 804 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
document.getElementById('year').textContent = new Date().getFullYear();
const tabs = [...document.querySelectorAll('.tabs a')];
const sections = tabs.map(tab => document.querySelector(tab.getAttribute('href')));
const observer = new IntersectionObserver(entries => {
const visible = entries.filter(entry => entry.isIntersecting)
.sort((a, b) => b.intersectionRatio - a.intersectionRatio)[0];
if (!visible) return;
tabs.forEach(tab => {
const active = tab.getAttribute('href') === `#${visible.target.id}`;
tab.classList.toggle('active', active);
if (active) tab.setAttribute('aria-current', 'page');
else tab.removeAttribute('aria-current');
});
}, { rootMargin: '-20% 0px -60%', threshold: [0, .1, .5] });
sections.forEach(section => section && observer.observe(section));