-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathanimate.js
32 lines (29 loc) · 839 Bytes
/
animate.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
const milestones = document.querySelectorAll('.timeline-item');
const max = milestones.length;
var idx = 0;
observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.intersectionRatio > 0) {
entry.target.classList.add('animate');
} else {
entry.target.classList.remove('animate');
}
});
});
milestones.forEach(milestone => {
observer.observe(milestone);
});
document.addEventListener("keydown", function(event) {
event.preventDefault();
const key = event.key;
if ((key === "ArrowLeft") || (key === "ArrowUp")) {
idx > 0 ? idx-- : 0;
var current = milestones[idx];
current.scrollIntoView();
}
if ((key === "ArrowRight") || (key === "ArrowDown")) {
var current = milestones[idx];
current.scrollIntoView();
idx < max - 1 ? idx++ : idx;
}
});