File size: 9,292 Bytes
6ad7b31 | 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 | // ===== CUSTOM CURSOR =====
const cursor = document.getElementById('cursor');
const cursorTrail = document.getElementById('cursorTrail');
document.addEventListener('mousemove', e => {
cursor.style.left = e.clientX + 'px';
cursor.style.top = e.clientY + 'px';
cursorTrail.style.left = e.clientX + 'px';
cursorTrail.style.top = e.clientY + 'px';
});
document.querySelectorAll('a, button, .glass-card, input, textarea').forEach(el => {
el.addEventListener('mouseenter', () => {
cursor.style.width = '20px';
cursor.style.height = '20px';
cursor.style.background = 'var(--cyan)';
cursorTrail.style.width = '50px';
cursorTrail.style.height = '50px';
});
el.addEventListener('mouseleave', () => {
cursor.style.width = '12px';
cursor.style.height = '12px';
cursor.style.background = 'var(--purple)';
cursorTrail.style.width = '36px';
cursorTrail.style.height = '36px';
});
});
// ===== PARTICLE CANVAS =====
const canvas = document.getElementById('particleCanvas');
const ctx = canvas.getContext('2d');
let particles = [];
let W, H;
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.size = Math.random() * 1.5 + 0.3;
this.speedX = (Math.random() - 0.5) * 0.4;
this.speedY = (Math.random() - 0.5) * 0.4;
this.opacity = Math.random() * 0.5 + 0.1;
this.color = Math.random() > 0.5 ? '245,158,11' : '14,165,233';
}
update() {
this.x += this.speedX;
this.y += this.speedY;
if (this.x < 0 || this.x > W || this.y < 0 || this.y > H) this.reset();
}
draw() {
ctx.beginPath();
ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
ctx.fillStyle = `rgba(${this.color},${this.opacity})`;
ctx.fill();
}
}
// Optimized particle count for buttery smooth 60 FPS performance
for (let i = 0; i < 45; i++) particles.push(new Particle());
function connectParticles() {
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 distSq = dx * dx + dy * dy;
if (distSq < 10000) {
const dist = Math.sqrt(distSq);
ctx.beginPath();
ctx.strokeStyle = `rgba(245,158,11,${0.15 * (1 - dist / 100)})`;
ctx.lineWidth = 0.5;
ctx.moveTo(particles[i].x, particles[i].y);
ctx.lineTo(particles[j].x, particles[j].y);
ctx.stroke();
}
}
}
}
function animateParticles() {
ctx.clearRect(0, 0, W, H);
particles.forEach(p => { p.update(); p.draw(); });
connectParticles();
requestAnimationFrame(animateParticles);
}
animateParticles();
// ===== NAVBAR SCROLL (Cached DOM queries & throttling) =====
const navbar = document.getElementById('navbar');
const cachedSections = document.querySelectorAll('section[id]');
let isScrolling = false;
window.addEventListener('scroll', () => {
if (!isScrolling) {
window.requestAnimationFrame(() => {
navbar.classList.toggle('scrolled', window.scrollY > 50);
updateActiveLink();
isScrolling = false;
});
isScrolling = true;
}
});
function updateActiveLink() {
const scrollY = window.scrollY + 100;
cachedSections.forEach(sec => {
const top = sec.offsetTop;
const height = sec.offsetHeight;
const id = sec.getAttribute('id');
const link = document.querySelector(`.nav-link[href="#${id}"]`);
if (link) {
if (scrollY >= top && scrollY < top + height) {
document.querySelectorAll('.nav-link').forEach(l => l.classList.remove('active'));
link.classList.add('active');
}
}
});
}
// ===== TYPEWRITER =====
const words = ['AI Systems 🤖', 'ML Models 🧠', 'Data Science Pipelines 📊', 'Deep Learning Architectures ⚡', 'Predictive Analytics 📈'];
let wordIndex = 0, charIndex = 0, isDeleting = false;
const typeEl = document.getElementById('typewriter');
function type() {
const current = words[wordIndex];
if (isDeleting) {
typeEl.textContent = current.substring(0, charIndex--);
if (charIndex < 0) { isDeleting = false; wordIndex = (wordIndex + 1) % words.length; setTimeout(type, 400); return; }
setTimeout(type, 60);
} else {
typeEl.textContent = current.substring(0, charIndex++);
if (charIndex > current.length) { isDeleting = true; setTimeout(type, 1800); return; }
setTimeout(type, 90);
}
}
type();
// ===== SCROLL REVEAL =====
const revealObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('revealed');
}
});
}, { threshold: 0.1, rootMargin: '0px 0px -50px 0px' });
document.querySelectorAll('.reveal-up, .reveal-left, .reveal-right').forEach(el => {
revealObserver.observe(el);
});
// ===== STAT COUNTER =====
const statObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const el = entry.target;
const target = parseInt(el.dataset.target);
let count = 0;
const step = target / 40;
const timer = setInterval(() => {
count += step;
if (count >= target) { count = target; clearInterval(timer); }
el.textContent = Math.floor(count);
}, 40);
statObserver.unobserve(el);
}
});
}, { threshold: 0.5 });
document.querySelectorAll('.stat-number').forEach(el => statObserver.observe(el));
// ===== SKILL BARS =====
const skillObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.querySelectorAll('.skill-fill').forEach(bar => {
bar.style.width = bar.dataset.width + '%';
});
skillObserver.unobserve(entry.target);
}
});
}, { threshold: 0.3 });
document.querySelectorAll('.skill-category').forEach(el => skillObserver.observe(el));
// ===== CONTACT FORM =====
const form = document.getElementById('contactForm');
form.addEventListener('submit', e => {
e.preventDefault();
const btn = document.getElementById('sendBtn');
const originalHTML = btn.innerHTML;
btn.innerHTML = '<span>Sending...</span>';
btn.disabled = true;
setTimeout(() => {
btn.innerHTML = '<span>✓ Message Sent!</span>';
btn.style.background = 'linear-gradient(135deg,#22c55e,#16a34a)';
form.reset();
setTimeout(() => {
btn.innerHTML = originalHTML;
btn.style.background = '';
btn.disabled = false;
}, 3000);
}, 1500);
});
// ===== HAMBURGER MENU =====
const hamburger = document.getElementById('hamburger');
hamburger.addEventListener('click', () => {
const links = document.querySelector('.nav-links');
const cta = document.querySelector('.nav-cta');
if (links.style.display === 'flex') {
links.style.display = 'none';
cta.style.display = 'none';
} else {
links.style.cssText = 'display:flex;flex-direction:column;position:absolute;top:70px;left:0;right:0;background:rgba(255,253,246,0.95);padding:20px;gap:20px;backdrop-filter:blur(20px);border-bottom:1px solid rgba(0,0,0,0.08);';
cta.style.display = 'none';
}
});
// ===== SMOOTH SCROLL FOR ANCHOR LINKS =====
document.querySelectorAll('a[href^="#"]').forEach(a => {
a.addEventListener('click', e => {
e.preventDefault();
const target = document.querySelector(a.getAttribute('href'));
if (target) target.scrollIntoView({ behavior: 'smooth' });
});
});
// ===== TILT EFFECT ON PROJECT CARDS =====
document.querySelectorAll('.project-card').forEach(card => {
card.addEventListener('mousemove', e => {
const rect = card.getBoundingClientRect();
const x = (e.clientX - rect.left) / rect.width - 0.5;
const y = (e.clientY - rect.top) / rect.height - 0.5;
card.style.transform = `perspective(600px) rotateY(${x * 8}deg) rotateX(${-y * 8}deg) translateY(-4px)`;
});
card.addEventListener('mouseleave', () => {
card.style.transform = '';
});
});
// ===== PARALLAX ON HERO GLOWS (Cached DOM queries) =====
const glow1 = document.querySelector('.glow-1');
const glow2 = document.querySelector('.glow-2');
document.addEventListener('mousemove', e => {
const xp = (e.clientX / window.innerWidth - 0.5) * 30;
const yp = (e.clientY / window.innerHeight - 0.5) * 30;
if (glow1) glow1.style.transform = `translate(${xp}px,${yp}px)`;
if (glow2) glow2.style.transform = `translate(${-xp}px,${-yp}px)`;
});
// ===== RESUME BUTTON HANDLER =====
const resumeBtn = document.getElementById('resumeBtn');
if (resumeBtn) {
resumeBtn.addEventListener('click', e => {
e.preventDefault();
const originalHTML = resumeBtn.innerHTML;
resumeBtn.innerHTML = '<span>Downloading...</span>';
setTimeout(() => {
resumeBtn.innerHTML = '<span>✓ Resume Downloaded</span>';
resumeBtn.style.background = 'linear-gradient(135deg,#22c55e,#16a34a)';
alert("Thank you for downloading my resume! Let's connect to discuss opportunities.");
setTimeout(() => {
resumeBtn.innerHTML = originalHTML;
resumeBtn.style.background = '';
}, 3000);
}, 1500);
});
}
|