-
Notifications
You must be signed in to change notification settings - Fork 1
/
animations.js
33 lines (30 loc) · 1.22 KB
/
animations.js
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
window.addEventListener("load", () => {
// Grabbing them animation elements to prep entrance animations
const entryAnimations = document.querySelectorAll('.animation');
// Initializing our IntersectionObserver
const observer = new IntersectionObserver((entries) => {
// Loop through sections to set up sequential entrance animations
const sections = Array.from(document.querySelectorAll('.content'));
for (let section of sections) {
// ...only sequential for elements that need the delay, tho
const fadeups = section.querySelectorAll('.animation.delay');
for (let count = 0; count < fadeups.length; count++) {
// delaying by 0.5s for that nice, flowing, "waterfall" kind of sequence.
fadeups[count].setAttribute('style', 'transition-delay: ' + count * 100 + 'ms');
}
}
entries.forEach(entry => {
// once we've observed the entry "intersecting" (within
// view of the viewport), toggle that visible class!
if (entry.isIntersecting) {
entry.target.classList.add('visible');
} else {
entry.target.classList.remove('visible');
}
});
});
entryAnimations.forEach(el => {
// observation time
observer.observe(el);
});
});