-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
46 lines (29 loc) · 910 Bytes
/
script.js
File metadata and controls
46 lines (29 loc) · 910 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
40
41
42
43
44
45
46
const sections = document.querySelectorAll("section");
const navLinks = document.querySelectorAll(".nav-link");
window.addEventListener("scroll", () => {
let current = "";
sections.forEach(section => {
const sectionTop = section.offsetTop;
const sectionHeight = section.clientHeight;
if(pageYOffset >= sectionTop - 200){
current = section.getAttribute("id");
}
});
navLinks.forEach(link => {
link.classList.remove("active");
if(link.getAttribute("href").includes(current)){
link.classList.add("active");
}
});
});
const reveals = document.querySelectorAll(".reveal");
window.addEventListener("scroll", () => {
reveals.forEach((element) => {
const windowHeight = window.innerHeight;
const revealTop = element.getBoundingClientRect().top;
const revealPoint = 120;
if(revealTop < windowHeight - revealPoint){
element.classList.add("active");
}
});
});