-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
415 lines (376 loc) · 14.9 KB
/
Copy pathscript.js
File metadata and controls
415 lines (376 loc) · 14.9 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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
// ══════════════════════════════════════════
// VENKATMOHAN VASAMSETTI — Portfolio JS
// Features: Particles, Cursor, Counters,
// Tabs, Skill Bars, Typed, Reveal, Form
// ══════════════════════════════════════════
(function () {
'use strict';
// ── Preloader ──────────────────────────
function initPreloader() {
window.addEventListener('load', () => {
setTimeout(() => {
const pl = document.getElementById('preloader');
if (pl) pl.classList.add('out');
}, 900);
});
}
// ── Particle Canvas ────────────────────
function initParticles() {
const canvas = document.getElementById('bgCanvas');
if (!canvas) return;
const ctx = canvas.getContext('2d');
let W, H, particles = [], mouse = { x: 0, y: 0 };
function resize() {
W = canvas.width = window.innerWidth;
H = canvas.height = window.innerHeight;
}
resize();
window.addEventListener('resize', resize);
class Particle {
constructor() { this.reset(); }
reset() {
this.x = Math.random() * W;
this.y = Math.random() * H;
this.r = Math.random() * 1.5 + 0.3;
this.vx = (Math.random() - 0.5) * 0.3;
this.vy = (Math.random() - 0.5) * 0.3;
this.alpha = Math.random() * 0.5 + 0.1;
this.color = Math.random() > 0.7 ? '#00e5c8' : '#4a6fa5';
}
update() {
this.x += this.vx;
this.y += this.vy;
if (this.x < 0 || this.x > W || this.y < 0 || this.y > H) this.reset();
// mouse repulsion
const dx = this.x - mouse.x, dy = this.y - mouse.y;
const dist = Math.sqrt(dx * dx + dy * dy);
if (dist < 100) {
this.x += dx / dist * 1.5;
this.y += dy / dist * 1.5;
}
}
draw() {
ctx.beginPath();
ctx.arc(this.x, this.y, this.r, 0, Math.PI * 2);
ctx.fillStyle = this.color;
ctx.globalAlpha = this.alpha;
ctx.fill();
}
}
for (let i = 0; i < 120; i++) particles.push(new Particle());
function drawLines() {
for (let i = 0; i < particles.length; i++) {
for (let j = i + 1; j < particles.length; j++) {
const dx = particles[i].x - particles[j].x;
const dy = particles[i].y - particles[j].y;
const dist = Math.sqrt(dx * dx + dy * dy);
if (dist < 110) {
ctx.beginPath();
ctx.moveTo(particles[i].x, particles[i].y);
ctx.lineTo(particles[j].x, particles[j].y);
ctx.strokeStyle = '#00e5c8';
ctx.globalAlpha = (1 - dist / 110) * 0.06;
ctx.lineWidth = 0.5;
ctx.stroke();
}
}
}
}
function animate() {
ctx.clearRect(0, 0, W, H);
ctx.globalAlpha = 1;
drawLines();
particles.forEach(p => { p.update(); p.draw(); });
ctx.globalAlpha = 1;
requestAnimationFrame(animate);
}
animate();
window.addEventListener('mousemove', e => {
mouse.x = e.clientX;
mouse.y = e.clientY;
});
}
// ── Custom Cursor ──────────────────────
function initCursor() {
const dot = document.getElementById('curDot');
const ring = document.getElementById('curRing');
if (!dot || !ring) return;
let mx = 0, my = 0, rx = 0, ry = 0;
window.addEventListener('mousemove', e => {
mx = e.clientX; my = e.clientY;
dot.style.left = mx + 'px';
dot.style.top = my + 'px';
});
function loop() {
rx += (mx - rx) * 0.12;
ry += (my - ry) * 0.12;
ring.style.left = rx + 'px';
ring.style.top = ry + 'px';
requestAnimationFrame(loop);
}
loop();
const hoverEls = document.querySelectorAll('a, button, .pcard, .ccard, .smcard, .sk-card, .tl-card');
hoverEls.forEach(el => {
el.addEventListener('mouseenter', () => { dot.classList.add('hover'); ring.classList.add('hover'); });
el.addEventListener('mouseleave', () => { dot.classList.remove('hover'); ring.classList.remove('hover'); });
});
}
// ── Header Scroll ──────────────────────
function initHeader() {
const hdr = document.getElementById('header');
let lastScroll = 0;
window.addEventListener('scroll', () => {
const s = window.scrollY;
hdr.classList.toggle('scrolled', s > 50);
lastScroll = s;
}, { passive: true });
}
// ── Mobile Drawer ──────────────────────
function initDrawer() {
const burger = document.getElementById('burger');
const drawer = document.getElementById('drawer');
const bg = document.getElementById('drawerBg');
if (!burger || !drawer) return;
const open = () => { drawer.classList.add('open'); bg.classList.add('show'); burger.classList.add('open'); document.body.style.overflow = 'hidden'; };
const close = () => { drawer.classList.remove('open'); bg.classList.remove('show'); burger.classList.remove('open'); document.body.style.overflow = ''; };
burger.addEventListener('click', () => drawer.classList.contains('open') ? close() : open());
bg.addEventListener('click', close);
drawer.querySelectorAll('a').forEach(a => a.addEventListener('click', close));
}
// ── Scroll Reveal ──────────────────────
function initReveal() {
const els = document.querySelectorAll(
'.reveal, .sec-hd, .about-grid, .tl-item, .smcard, .pcard, .ccard, .contact-grid, .hero-card, .hero-l'
);
els.forEach(el => {
if (!el.classList.contains('reveal')) el.classList.add('reveal');
});
const io = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (!entry.isIntersecting) return;
const siblings = [...(entry.target.parentElement?.children || [])].filter(c => c.classList.contains('reveal'));
const idx = siblings.indexOf(entry.target);
setTimeout(() => entry.target.classList.add('in'), Math.min(idx * 80, 400));
io.unobserve(entry.target);
});
}, { threshold: 0.07 });
els.forEach(el => io.observe(el));
}
// ── Counter Animation ──────────────────
function initCounters() {
const counters = document.querySelectorAll('.counter[data-target]');
const io = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (!entry.isIntersecting) return;
const el = entry.target;
const target = parseFloat(el.dataset.target);
const decimal = parseInt(el.dataset.decimal || '0');
const dur = 1400, steps = 70;
let step = 0;
const timer = setInterval(() => {
step++;
const t = step / steps;
const ease = 1 - Math.pow(1 - t, 3);
el.textContent = (target * ease).toFixed(decimal);
if (step >= steps) { el.textContent = target.toFixed(decimal); clearInterval(timer); }
}, dur / steps);
io.unobserve(el);
});
}, { threshold: 0.5 });
counters.forEach(el => io.observe(el));
}
// ── Skill Bars ─────────────────────────
function initSkillBars() {
const bars = document.querySelectorAll('.sb-item');
const io = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (!entry.isIntersecting) return;
const fill = entry.target.querySelector('.sb-fill');
const w = entry.target.dataset.width || '80';
if (fill) setTimeout(() => fill.style.width = w + '%', 200);
io.unobserve(entry.target);
});
}, { threshold: 0.3 });
bars.forEach(b => io.observe(b));
}
// ── Resume Tabs ────────────────────────
function initTabs() {
const tabs = document.querySelectorAll('.rtab');
const contents = document.querySelectorAll('.rtab-content');
tabs.forEach(tab => {
tab.addEventListener('click', () => {
tabs.forEach(t => t.classList.remove('active'));
contents.forEach(c => c.classList.remove('active'));
tab.classList.add('active');
const target = document.getElementById('tab-' + tab.dataset.tab);
if (target) {
target.classList.add('active');
// re-trigger reveals inside new tab
target.querySelectorAll('.reveal').forEach(el => {
el.classList.remove('in');
setTimeout(() => el.classList.add('in'), 50);
});
}
});
});
}
// ── Active Nav Highlight ───────────────
function initActiveNav() {
const sections = document.querySelectorAll('section[id]');
const links = document.querySelectorAll('.hdr-nav a:not(.nav-cta)');
const io = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (entry.isIntersecting) {
links.forEach(l => {
l.style.color = '';
if (l.getAttribute('href') === '#' + entry.target.id) l.style.color = 'var(--cyan)';
});
}
});
}, { rootMargin: '-40% 0px -55% 0px' });
sections.forEach(s => io.observe(s));
}
// ── Scroll Top ─────────────────────────
function initScrollTop() {
const btn = document.getElementById('scrollTop');
if (!btn) return;
window.addEventListener('scroll', () => btn.classList.toggle('show', window.scrollY > 500), { passive: true });
btn.addEventListener('click', () => window.scrollTo({ top: 0, behavior: 'smooth' }));
}
// ── Contact Form ───────────────────────
function initForm() {
const form = document.getElementById('contactForm');
const note = document.getElementById('cformNote');
if (!form) return;
form.addEventListener('submit', e => {
e.preventDefault();
const btn = form.querySelector('button[type=submit]');
const orig = btn.innerHTML;
btn.innerHTML = '<span>Sending…</span> <i class="fas fa-spinner fa-spin"></i>';
btn.disabled = true;
setTimeout(() => {
note.textContent = '✓ Message sent! I\'ll get back to you soon.';
btn.innerHTML = '<span>Sent!</span> <i class="fas fa-check"></i>';
btn.style.background = '#059652';
form.reset();
setTimeout(() => {
btn.innerHTML = orig;
btn.style.background = '';
btn.disabled = false;
note.textContent = '';
}, 4000);
}, 1000);
});
}
// ── Smooth Anchors ─────────────────────
function initAnchors() {
document.querySelectorAll('a[href^="#"]').forEach(a => {
a.addEventListener('click', e => {
const t = document.querySelector(a.getAttribute('href'));
if (t) { e.preventDefault(); t.scrollIntoView({ behavior: 'smooth', block: 'start' }); }
});
});
}
// ── Tilt Cards ─────────────────────────
function initTilt() {
document.querySelectorAll('.pcard, .hero-card').forEach(card => {
card.addEventListener('mousemove', e => {
const r = card.getBoundingClientRect();
const x = (e.clientX - r.left) / r.width - 0.5;
const y = (e.clientY - r.top) / r.height - 0.5;
card.style.transform = `perspective(800px) rotateY(${x * 8}deg) rotateX(${-y * 8}deg) translateY(-5px)`;
});
card.addEventListener('mouseleave', () => {
card.style.transform = '';
});
});
}
// ── Typing Effect in Hero ──────────────
function initTyping() {
// The CSS handles the word cycling animation for .role-words
// This adds a subtle text shimmer to hero name on load
const name = document.querySelector('.hero-name');
if (!name) return;
}
// ── Page Transition on Load ────────────
function initPageLoad() {
document.body.style.opacity = '0';
document.body.style.transition = 'opacity 0.5s ease';
window.addEventListener('load', () => {
setTimeout(() => { document.body.style.opacity = '1'; }, 100);
});
}
// ── Scroll-based header progress bar ──
function initProgressBar() {
const bar = document.createElement('div');
bar.style.cssText = `
position:fixed;top:0;left:0;height:2px;width:0%;
background:linear-gradient(to right,#00e5c8,#00bfa5);
z-index:1000;transition:width 0.1s linear;pointer-events:none;
`;
document.body.appendChild(bar);
window.addEventListener('scroll', () => {
const total = document.documentElement.scrollHeight - window.innerHeight;
bar.style.width = ((window.scrollY / total) * 100) + '%';
}, { passive: true });
}
// ── Init All ───────────────────────────
function init() {
initPageLoad();
initPreloader();
initParticles();
initCursor();
initHeader();
initDrawer();
initReveal();
initCounters();
initSkillBars();
initTabs();
initActiveNav();
initScrollTop();
initForm();
initAnchors();
initTilt();
initTyping();
initProgressBar();
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
})();
// ── Certificate Modal ──────────────────
function initCertModal() {
const modal = document.getElementById('certModal');
const overlay = document.getElementById('cmOverlay');
const closeBtn= document.getElementById('cmClose');
const img = document.getElementById('cmImg');
const caption = document.getElementById('cmCaption');
if (!modal) return;
document.querySelectorAll('.view-cert-btn').forEach(btn => {
btn.addEventListener('click', () => {
const card = btn.closest('.ccard');
const src = card.dataset.cert;
const cap = card.dataset.caption || '';
if (!src) {
alert('Certificate image not available. Please upload the certificate image to GitHub.');
return;
}
img.src = src;
caption.textContent = cap;
modal.classList.add('open');
document.body.style.overflow = 'hidden';
});
});
const close = () => { modal.classList.remove('open'); document.body.style.overflow = ''; img.src = ''; };
closeBtn.addEventListener('click', close);
overlay.addEventListener('click', close);
document.addEventListener('keydown', e => { if (e.key === 'Escape') close(); });
}
// Call it
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initCertModal);
} else {
initCertModal();
}