-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
45 lines (39 loc) · 1.25 KB
/
script.js
File metadata and controls
45 lines (39 loc) · 1.25 KB
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
// ===== Scroll Spy: Highlight active nav link =====
const sections = document.querySelectorAll("section");
const navLinks = document.querySelectorAll(".nav-link");
window.addEventListener("scroll", () => {
let current = "";
sections.forEach((section) => {
const sectionTop = section.offsetTop - 100; // navbar height offset
const sectionHeight = section.clientHeight;
if (window.scrollY >= sectionTop && window.scrollY < sectionTop + sectionHeight) {
current = section.getAttribute("id");
}
});
navLinks.forEach((link) => {
link.classList.remove("active");
if (link.getAttribute("href") === `#${current}`) {
link.classList.add("active");
}
});
});
// ===== Contact Form Demo =====
const form = document.querySelector("form");
if (form) {
form.addEventListener("submit", function (e) {
e.preventDefault();
alert("Message sent! (Demo only)");
form.reset(); // clear form after submit (extra)
});
}
// ===== Typing Effect in Hero Section =====
const text = "A Passionate Web Developer";
let i = 0;
function typeWriter() {
if (i < text.length) {
document.getElementById("typed-text").innerHTML += text.charAt(i);
i++;
setTimeout(typeWriter, 100);
}
}
window.addEventListener("load", typeWriter);