-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
27 lines (23 loc) · 783 Bytes
/
script.js
File metadata and controls
27 lines (23 loc) · 783 Bytes
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
const header = document.querySelector('[data-header]');
const revealItems = document.querySelectorAll('.reveal');
function updateHeader() {
header?.classList.toggle('is-scrolled', window.scrollY > 12);
}
if ('IntersectionObserver' in window) {
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add('is-visible');
observer.unobserve(entry.target);
}
});
},
{ threshold: 0.18 }
);
revealItems.forEach((item) => observer.observe(item));
} else {
revealItems.forEach((item) => item.classList.add('is-visible'));
}
updateHeader();
window.addEventListener('scroll', updateHeader, { passive: true });