-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
307 lines (267 loc) · 9.68 KB
/
Copy pathscript.js
File metadata and controls
307 lines (267 loc) · 9.68 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
document.addEventListener("DOMContentLoaded", () => {
console.log("Portfolio loaded smoothly!");
// --- NAVBAR SCROLL EFFECT ---
const navbar = document.getElementById("navbar");
window.addEventListener("scroll", () => {
if (window.scrollY > 60) {
navbar.classList.add("scrolled");
} else {
navbar.classList.remove("scrolled");
}
});
const prefersReducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
// --- HERO PARALLAX ---
const heroDots = document.querySelector('.hero-bg-dots');
if (heroDots) {
let ticking = false;
window.addEventListener('scroll', () => {
if (!ticking) {
requestAnimationFrame(() => {
const scrollY = window.scrollY;
if (scrollY < window.innerHeight * 1.2) {
heroDots.style.transform = `scale(2) translate(${scrollY * 0.012}px, ${scrollY * 0.02}px)`;
}
ticking = false;
});
ticking = true;
}
}, { passive: true });
}
// --- MOBILE MENU TOGGLE ---
const hamburger = document.querySelector(".nav-hamburger");
const mobileMenu = document.getElementById("mobile-menu");
const mobileLinks = document.querySelectorAll(".mobile-nav-link");
function toggleMenu() {
const isOpen = mobileMenu.classList.toggle("open");
hamburger.innerHTML = isOpen ? "✕" : "☰";
document.body.style.overflow = isOpen ? "hidden" : ""; // prevent background scroll
}
hamburger.addEventListener("click", toggleMenu);
// Close menu when a link is clicked
mobileLinks.forEach(link => {
link.addEventListener("click", () => {
mobileMenu.classList.remove("open");
hamburger.innerHTML = "☰";
document.body.style.overflow = "";
});
});
// Close menu when clicking directly on the overlay background
mobileMenu.addEventListener("click", (e) => {
if (e.target === mobileMenu) {
mobileMenu.classList.remove("open");
hamburger.innerHTML = "☰";
document.body.style.overflow = "";
}
});
// --- ACTIVE LINK TRACKING (IntersectionObserver) ---
const sections = document.querySelectorAll("section");
const navLinks = document.querySelectorAll(".nav-link"); // desktop links
const observerOptions = {
root: null,
rootMargin: "0px",
threshold: 0.5 // Trigger when section is 50% in viewport
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
// Remove active class from all links
navLinks.forEach(link => link.classList.remove("active"));
// Add active class to corresponding link
const targetId = entry.target.getAttribute("id");
const activeLink = document.querySelector(`.nav-link[href="#${targetId}"]`);
if (activeLink) {
activeLink.classList.add("active");
}
}
});
}, observerOptions);
sections.forEach(sec => observer.observe(sec));
// --- SECTION CROSSFADE ---
const allSections = document.querySelectorAll('section');
const crossfadeObs = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
allSections.forEach(s => s.classList.add('section-dim'));
entry.target.classList.remove('section-dim');
}
});
}, { threshold: 0.3 });
if (!prefersReducedMotion) {
allSections.forEach(s => crossfadeObs.observe(s));
}
// --- HERO TYPEWRITER EFFECT ---
// --- HERO TYPEWRITER EFFECT ---
const phrases = [
"Systems builder",
"Mechanical Engineering Undergrad",
"Edge ML · CFD · Deployed tools"
];
const typewriterText = document.getElementById("typewriter-text");
const typewriterCursor = document.querySelector(".typewriter-cursor");
if (typewriterText) {
let phraseIndex = 0;
let charIndex = 0;
let isDeleting = false;
function setCursorBlink(blinking) {
if (typewriterCursor) {
typewriterCursor.classList.toggle("blinking", blinking);
}
}
function typeEffect() {
const currentPhrase = phrases[phraseIndex];
if (isDeleting) {
charIndex--;
typewriterText.textContent = currentPhrase.substring(0, charIndex);
if (charIndex === 0) {
isDeleting = false;
phraseIndex = (phraseIndex + 1) % phrases.length;
setCursorBlink(true);
setTimeout(typeEffect, 400);
return;
}
setCursorBlink(false);
setTimeout(typeEffect, 35);
} else {
charIndex++;
typewriterText.textContent = currentPhrase.substring(0, charIndex);
if (charIndex === currentPhrase.length) {
setCursorBlink(true);
setTimeout(() => {
isDeleting = true;
setCursorBlink(false);
setTimeout(typeEffect, 35);
}, 1800);
return;
}
setCursorBlink(false);
setTimeout(typeEffect, 70);
}
}
setCursorBlink(true);
setTimeout(typeEffect, 1000);
}
// --- PROJECTS FILTERING ---
const filterTabs = document.querySelectorAll(".filter-tab");
const projectCards = document.querySelectorAll(".project-card");
filterTabs.forEach(tab => {
tab.addEventListener("click", () => {
filterTabs.forEach(t => t.classList.remove("active"));
tab.classList.add("active");
const filter = tab.getAttribute("data-filter");
projectCards.forEach(card => {
const matches = filter === "all" || card.getAttribute("data-tag") === filter;
if (matches) {
card.classList.remove("is-hidden");
} else {
card.classList.add("is-hidden");
}
});
});
});
// --- CARD SCROLL ANIMATION ---
const cardObserver = new IntersectionObserver((entries) => {
entries.forEach((entry, i) => {
if (entry.isIntersecting) {
setTimeout(() => {
entry.target.classList.add("is-visible");
}, prefersReducedMotion ? 0 : i * 80);
cardObserver.unobserve(entry.target);
}
});
}, { threshold: 0.08, rootMargin: '0px 0px -40px 0px' });
projectCards.forEach(card => cardObserver.observe(card));
// --- MAGNETIC CARD HOVER ---
const projectCardEls = document.querySelectorAll('.project-card');
projectCardEls.forEach(card => {
card.addEventListener('mousemove', (e) => {
const rect = card.getBoundingClientRect();
const x = e.clientX - rect.left - rect.width / 2;
const y = e.clientY - rect.top - rect.height / 2;
const tiltX = (y / rect.height) * 6;
const tiltY = -(x / rect.width) * 6;
card.style.transform = `translateY(-3px) perspective(600px) rotateX(${tiltX}deg) rotateY(${tiltY}deg)`;
});
card.addEventListener('mouseleave', () => {
card.style.transform = '';
card.style.transition = 'transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94)';
setTimeout(() => { card.style.transition = ''; }, 400);
});
});
// --- CONTACT CARD GLOW ---
const contactCards = document.querySelectorAll('.contact-card');
contactCards.forEach(card => {
card.addEventListener('mousemove', (e) => {
const rect = card.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
card.style.background = `radial-gradient(circle at ${x}px ${y}px, rgba(245,166,35,0.08) 0%, #111827 60%)`;
});
card.addEventListener('mouseleave', () => {
card.style.background = '';
});
});
// --- TEXT SPLIT STAGGER ---
function splitAndAnimate(selector) {
const els = document.querySelectorAll(selector);
els.forEach(el => {
const words = el.textContent.trim().split(' ');
el.innerHTML = words.map((word, i) =>
`<span class="word-wrap"><span class="word" style="transition-delay:${i * 0.04}s">${word}</span></span>`
).join(' ');
});
}
splitAndAnimate('.hero-name');
splitAndAnimate('.section-header h2');
setTimeout(() => {
document.querySelectorAll('.hero-name .word').forEach(w => {
w.classList.add('word-visible');
});
}, 100);
// --- SCROLL REVEAL ---
const revealEls = document.querySelectorAll('.reveal');
const revealObs = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('is-visible');
// Trigger word animations inside section headers
entry.target.querySelectorAll('.word').forEach(w => {
w.classList.add('word-visible');
});
revealObs.unobserve(entry.target);
}
});
}, { threshold: 0.12, rootMargin: '0px 0px -40px 0px' });
revealEls.forEach(el => revealObs.observe(el));
// --- CUSTOM CURSOR ---
const cursorDot = document.getElementById("cursor-dot");
const cursorOutline = document.getElementById("cursor-outline");
// Only run cursor logic if fine pointer (mouse) is present
if (window.matchMedia("(pointer: fine)").matches) {
window.addEventListener("mousemove", (e) => {
const posX = e.clientX;
const posY = e.clientY;
cursorDot.style.left = `${posX}px`;
cursorDot.style.top = `${posY}px`;
cursorOutline.style.left = `${posX}px`;
cursorOutline.style.top = `${posY}px`;
cursorOutline.style.opacity = '1';
});
// Hover effect on links and buttons
const interactiveElements = document.querySelectorAll("a, button, .filter-tab, .contact-card");
interactiveElements.forEach((el) => {
el.addEventListener("mouseenter", () => {
document.body.classList.add("cursor-hover-state");
});
el.addEventListener("mouseleave", () => {
document.body.classList.remove("cursor-hover-state");
});
// Safety reset
el.addEventListener("click", () => {
document.body.classList.remove("cursor-hover-state");
})
});
} else {
// Ensure body cursor isn't hidden on touch devices
document.body.style.cursor = 'auto';
}
});