-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
83 lines (67 loc) · 2.26 KB
/
script.js
File metadata and controls
83 lines (67 loc) · 2.26 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* =====================
TYPING EFFECT (HOME)
===================== */
const typingElement = document.getElementById("typing-text");
const textToType = "Sujan Kumar Roy";
if (typingElement) {
let index = 0;
function type() {
if (index < textToType.length) {
typingElement.textContent += textToType.charAt(index);
index++;
setTimeout(type, 120);
}
}
window.addEventListener("load", type);
}
/* =====================
FADE-IN ON SCROLL
===================== */
const observer = new IntersectionObserver(
entries => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add("show");
}
});
},
{ threshold: 0.15 }
);
document.querySelectorAll(".fade-in").forEach(el => observer.observe(el));
/* =====================
DYNAMIC ACTIVE NAV LINK ON SCROLL
===================== */
const sections = document.querySelectorAll("section, header");
const navLinks = document.querySelectorAll(".navbar ul li a");
window.addEventListener("scroll", () => {
let current = "";
sections.forEach(section => {
const sectionTop = section.offsetTop;
const sectionHeight = section.clientHeight;
// Check if the scroll position is within this section
if (scrollY >= sectionTop - 150) {
current = section.getAttribute("id");
}
});
navLinks.forEach(link => {
link.classList.remove("active");
if (link.getAttribute("href") === `#${current}`) {
link.classList.add("active");
}
});
});
/* =====================
CONTACT FORM (MAILTO)
===================== */
const contactForm = document.getElementById("contact-form");
if (contactForm) {
contactForm.addEventListener("submit", function (e) {
e.preventDefault();
const name = document.getElementById("name").value.trim();
const message = document.getElementById("message").value.trim();
if (!name || !message) return;
const subject = encodeURIComponent("Portfolio Message from " + name);
const body = encodeURIComponent(message);
window.location.href = `mailto:sujanroy63836@gmail.com?subject=${subject}&body=${body}`;
});
}