-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
30 lines (26 loc) · 752 Bytes
/
Copy pathscript.js
File metadata and controls
30 lines (26 loc) · 752 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
const navLinks = document.querySelectorAll(".nav-link");
const sections = document.querySelectorAll("section");
window.addEventListener("scroll", () => {
let current = "";
sections.forEach((section) => {
const sectionTop = section.offsetTop - 100;
if (pageYOffset >= sectionTop) {
current = section.getAttribute("id");
}
});
navLinks.forEach((link) => {
link.classList.remove("active");
if (link.getAttribute("href").includes(current)) {
link.classList.add("active");
}
});
});
let i = 0;
function type() {
if (i < text.length) {
introEl.textContent += text.charAt(i);
i++;
setTimeout(type, 45); // typing speed (ms per character)
}
}
window.addEventListener("DOMContentLoaded", type);