-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
60 lines (49 loc) · 1.95 KB
/
script.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const nav = document.querySelector("nav");
const navLinks = document.querySelectorAll(".nav-links li");
const menu = document.querySelector("#menu");
document.body.addEventListener("click", (e) => {
if (!menu.contains(e.target) & !nav.contains(e.target)) {
nav.classList.remove("active");
menu.classList.remove("active");
} else if (menu.contains(e.target)) {
nav.classList.toggle("active");
menu.classList.toggle("active");
}
});
navLinks.forEach((link) => link.addEventListener("click", addActiveClass));
function addActiveClass() {
navLinks.forEach((link) => link.classList.remove("active"));
this.classList.add("active");
}
// animation for vertical line 📏 & circles ⚪
const verticalLine = document.querySelector(".vertical");
const circles = document.querySelectorAll(".circle");
const horizontalLines = document.querySelectorAll(".horizontal");
const startingPoint = document.querySelector("#home").offsetHeight / 2;
let activeIndex = 0;
/// ** Description **
/**
* animation will start at height/2 of the Home page.
* when scrollAmount >= height of a feature card
* we want to increment active Index and
* then animate vertical line and the circles.
*/
function scrollEffect() {
const scrollAmt = scrollY - startingPoint;
if (scrollAmt < 0) {
activeIndex = 0;
circles.forEach((circle) => circle.classList.remove("active"));
horizontalLines.forEach((circle) => circle.classList.remove("active"));
verticalLine.style.height = 0;
return;
}
const amtToScroll =
document.querySelector(".feature").offsetHeight * (activeIndex + 1);
if (scrollAmt >= amtToScroll) {
activeIndex = Math.min(activeIndex + 1, circles.length);
verticalLine.style.height = `${(activeIndex * 100) / circles.length}%`;
circles[activeIndex - 1].classList.add("active");
horizontalLines[activeIndex - 1].classList.add("active");
}
}
window.onscroll = scrollEffect;