-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
310 lines (258 loc) · 8.41 KB
/
script.js
File metadata and controls
310 lines (258 loc) · 8.41 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
308
309
310
/* ===== Scroll Progress ===== */
const progressBar = document.getElementById("progress");
if (progressBar) {
window.addEventListener("scroll", () => {
const scrollTop = window.scrollY;
const height = document.documentElement.scrollHeight - window.innerHeight;
progressBar.style.width = (scrollTop / height) * 100 + "%";
});
}
/* ===== Hero Animations (GSAP) ===== */
document.addEventListener("DOMContentLoaded", () => {
if (typeof gsap !== "undefined") {
const tl = gsap.timeline({ defaults: { ease: "power3.out" } });
gsap.set(".reveal-text", { y: 30, opacity: 0 });
gsap.set(".sphere", { scale: 0.8, opacity: 0 });
gsap.set(".glow-left, .glow-right", { opacity: 0 });
tl.to(".reveal-text", {
y: 0,
opacity: 1,
duration: 0.8,
stagger: 0.15,
delay: 0.3
})
.to(".sphere", {
scale: 1,
opacity: 1,
duration: 1.2,
ease: "back.out(1.3)"
}, "-=0.5")
.to(".glow-left, .glow-right", {
opacity: 1,
duration: 1.5,
}, "-=0.8");
}
});
/* ===== Nav Link Active State ===== */
// Safety: Ensure active class is set based on current path if not already
const currentPath = window.location.pathname.split("/").pop() || "index.html";
document.querySelectorAll('.nav-links a').forEach(link => {
const linkHref = link.getAttribute('href');
if (linkHref === currentPath) {
document.querySelectorAll('.nav-links a').forEach(l => l.classList.remove('active'));
link.classList.add('active');
}
});
/* ===== Card Interaction ===== */
document.querySelectorAll(".card").forEach(card => {
card.addEventListener("click", () => {
document.querySelectorAll(".card").forEach(c => c.classList.remove("active"));
card.classList.add("active");
});
});
/* ===== Skill Hover ===== */
document.querySelectorAll(".skills span").forEach(skill => {
skill.addEventListener("mouseenter", () => skill.classList.add("active"));
skill.addEventListener("mouseleave", () => skill.classList.remove("active"));
});
/* ===== Contact Interaction ===== */
document.querySelectorAll(".contact-item").forEach(item => {
item.addEventListener("click", () => {
item.style.color = "#5b7cfa";
});
});
/* ===== Contact Form Interaction ===== */
const form = document.querySelector(".contact-form");
if (form) {
form.addEventListener("submit", e => {
e.preventDefault();
const button = form.querySelector("button");
const originalText = button.innerText;
button.innerText = "Sending...";
button.disabled = true;
const formData = new FormData(form);
fetch("https://formsubmit.co/ajax/7a41ceb9fada0b818acd10ed3315869b", {
method: "POST",
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: JSON.stringify(Object.fromEntries(formData))
})
.then(response => response.json())
.then(data => {
button.innerText = "Message Sent ✓";
button.style.background = "#6fd1c7";
form.reset();
setTimeout(() => {
button.innerText = originalText;
button.style.background = "";
button.disabled = false;
}, 5000);
})
.catch(error => {
console.error('Error:', error);
button.innerText = "Error! Try again.";
button.style.background = "#ff6b6b";
setTimeout(() => {
button.innerText = originalText;
button.style.background = "";
button.disabled = false;
}, 3000);
});
});
}
// Scroll reveal animation for inner elements
const revealElements = document.querySelectorAll('.reveal');
if (revealElements && revealElements.length) {
const revealObserver = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('in-view');
revealObserver.unobserve(entry.target);
}
});
}, { threshold: 0.15 });
revealElements.forEach(el => revealObserver.observe(el));
}
/* ===== Orb Animation ===== */
const orb = document.querySelector(".orb");
if (orb && typeof gsap !== "undefined") {
orb.addEventListener("mouseenter", () => {
gsap.to(".orb", {
scale: 1.08,
duration: 0.4,
ease: "power2.out"
});
});
orb.addEventListener("mouseleave", () => {
gsap.to(".orb", {
scale: 1,
duration: 0.4
});
});
}
/* ===== Status Text ===== */
const texts = [
"Available for opportunities",
"Building clean UI & interactions",
"Focused on frontend mastery",
"Learning. Building. Improving."
];
let index = 0;
const statusText = document.getElementById("statusText");
if (statusText) {
setInterval(() => {
index = (index + 1) % texts.length;
statusText.textContent = texts[index];
}, 3500);
}
/* ===== Project Row Animation ===== */
const projectRows = document.querySelectorAll('.project-row');
const observer1 = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('show');
}
});
}, { threshold: 0.2 });
projectRows.forEach(row => observer1.observe(row));
/* ===== Page Transition ===== */
document.addEventListener("DOMContentLoaded", () => {
requestAnimationFrame(() => {
document.body.classList.add("loaded");
});
});
document.querySelectorAll('a').forEach(anchor => {
anchor.addEventListener('click', function (e) {
const href = this.getAttribute('href');
const target = this.getAttribute('target');
if (href &&
!href.startsWith('#') &&
!href.startsWith('mailto:') &&
!href.startsWith('tel:') &&
!href.startsWith('javascript:') &&
target !== '_blank') {
e.preventDefault();
document.body.classList.remove('loaded');
setTimeout(() => {
window.location.href = href;
}, 400);
}
});
});
/* ===== Skill Tag Hover Colors ===== */
const skillTags = document.querySelectorAll('.skill-tag');
skillTags.forEach(tag => {
const color = tag.getAttribute('data-color');
const icon = tag.querySelector('i');
tag.addEventListener('mouseenter', () => {
tag.style.borderColor = color;
tag.style.boxShadow = `0 4px 15px ${color}40`; // 40 is hex opacity
if (icon) icon.style.color = color;
});
tag.addEventListener('mouseleave', () => {
tag.style.borderColor = 'rgba(255, 255, 255, 0.05)';
tag.style.boxShadow = 'none';
if (icon) icon.style.color = '';
});
});
/* ===== Magnetic Buttons ===== */
const buttons = document.querySelectorAll('.primary-btn, .secondary-btn, .nav-links a');
buttons.forEach(btn => {
btn.addEventListener('mousemove', (e) => {
const rect = btn.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
// Calculate distance from center
const centerX = rect.width / 2;
const centerY = rect.height / 2;
const deltaX = (x - centerX) * 0.2; // Move 20% of cursor distance
const deltaY = (y - centerY) * 0.2;
btn.style.transform = `translate(${deltaX}px, ${deltaY}px)`;
});
btn.addEventListener('mouseleave', () => {
btn.style.transform = 'translate(0, 0)';
});
});
/* ===== Mobile Menu Toggle ===== */
const menuToggle = document.querySelector('.menu-toggle');
const navLinks = document.querySelector('.nav-links');
if (menuToggle && navLinks) {
menuToggle.addEventListener('click', () => {
navLinks.classList.toggle('active');
// Animate toggle icon
const icon = menuToggle.querySelector('i');
if (icon) {
if (navLinks.classList.contains('active')) {
icon.classList.remove('fa-bars');
icon.classList.add('fa-times');
} else {
icon.classList.remove('fa-times');
icon.classList.add('fa-bars');
}
}
});
// Close menu when clicking outside
document.addEventListener('click', (e) => {
if (!menuToggle.contains(e.target) && !navLinks.contains(e.target) && navLinks.classList.contains('active')) {
navLinks.classList.remove('active');
const icon = menuToggle.querySelector('i');
if (icon) {
icon.classList.remove('fa-times');
icon.classList.add('fa-bars');
}
}
});
// Close menu when clicking a link
navLinks.querySelectorAll('a').forEach(link => {
link.addEventListener('click', () => {
navLinks.classList.remove('active');
const icon = menuToggle.querySelector('i');
if (icon) {
icon.classList.remove('fa-times');
icon.classList.add('fa-bars');
}
});
});
}