-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathutils.js
More file actions
39 lines (32 loc) · 891 Bytes
/
utils.js
File metadata and controls
39 lines (32 loc) · 891 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
28
29
30
31
32
33
34
35
36
37
38
39
// peek-a-boo!
const aElems = document.getElementsByTagName('section');
const observer = new IntersectionObserver(
(entries) => {
entries.forEach(entry => {
const elem = entry.target;
if (entry.isIntersecting) {
elem.classList.add('opacity-100');
elem.classList.remove('opacity-0');
} else {
elem.classList.remove('opacity-100');
elem.classList.add('opacity-0');
}
});
},
{
threshold: 0.1
}
);
// Observe each section individually
Array.from(aElems).forEach(elem => {
observer.observe(elem);
});
// gradient fun
const bg = document.getElementById('hero');
window.addEventListener('scroll', () => {
const scrollY = window.scrollY;
const fadeStart = 0;
const fadeEnd = 300;
const opacity = Math.max(0, 1 - (scrollY - fadeStart) / (fadeEnd - fadeStart));
bg.style.opacity = opacity;
});