-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
182 lines (166 loc) · 8.41 KB
/
script.js
File metadata and controls
182 lines (166 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
// ─── Loader ───────────────────────────────────────────────
window.addEventListener('load', () => {
setTimeout(() => {
document.getElementById('loader').classList.add('hide');
}, 1800);
});
// ─── Scroll Progress ──────────────────────────────────────
const scrollBar = document.getElementById('scroll-progress');
window.addEventListener('scroll', () => {
const pct = (window.scrollY / (document.body.scrollHeight - window.innerHeight)) * 100;
scrollBar.style.width = pct + '%';
});
// ─── Custom Cursor ────────────────────────────────────────
const cur = document.getElementById('cursor');
const curF = document.getElementById('cursor-follower');
let mx = 0, my = 0, fx = 0, fy = 0;
window.addEventListener('mousemove', e => { mx = e.clientX; my = e.clientY; cur.style.left = mx + 'px'; cur.style.top = my + 'px'; });
(function animCursor() {
fx += (mx - fx) * 0.12; fy += (my - fy) * 0.12;
curF.style.left = fx + 'px'; curF.style.top = fy + 'px';
requestAnimationFrame(animCursor);
})();
document.querySelectorAll('a,button,.project-card,.ach-card').forEach(el => {
el.addEventListener('mouseenter', () => { curF.style.width = '50px'; curF.style.height = '50px'; });
el.addEventListener('mouseleave', () => { curF.style.width = '30px'; curF.style.height = '30px'; });
});
// ─── Navbar ───────────────────────────────────────────────
const navbar = document.getElementById('navbar');
const hamburger = document.getElementById('hamburger');
const navLinks = document.getElementById('nav-links');
window.addEventListener('scroll', () => {
navbar.classList.toggle('scrolled', window.scrollY > 50);
document.getElementById('backToTop').classList.toggle('show', window.scrollY > 400);
});
hamburger.addEventListener('click', () => {
hamburger.classList.toggle('open');
navLinks.classList.toggle('open');
});
navLinks.querySelectorAll('.nav-link').forEach(l => {
l.addEventListener('click', () => { navLinks.classList.remove('open'); hamburger.classList.remove('open'); });
});
// ─── Active Nav on Scroll ─────────────────────────────────
const sections = document.querySelectorAll('section[id]');
const navItems = document.querySelectorAll('.nav-link');
const observer = new IntersectionObserver(entries => {
entries.forEach(e => {
if (e.isIntersecting) {
navItems.forEach(n => n.classList.remove('active'));
const active = document.querySelector(`.nav-link[href="#${e.target.id}"]`);
if (active) active.classList.add('active');
}
});
}, { threshold: 0.4 });
sections.forEach(s => observer.observe(s));
// ─── Theme Toggle ─────────────────────────────────────────
const themeToggle = document.getElementById('themeToggle');
let dark = true;
themeToggle.addEventListener('click', () => {
dark = !dark;
document.documentElement.setAttribute('data-theme', dark ? '' : 'light');
themeToggle.innerHTML = dark ? '<i class="fas fa-moon"></i>' : '<i class="fas fa-sun"></i>';
});
// ─── Typewriter ───────────────────────────────────────────
const words = ['Software Developer', 'AI & ML Enthusiast', 'Open Source Contributor', 'Google ELP Co-Lead', 'Tech Community Builder'];
let wi = 0, ci = 0, del = false;
const tw = document.getElementById('typewriter');
function typeLoop() {
const word = words[wi];
tw.textContent = del ? word.slice(0, ci--) : word.slice(0, ci++);
if (!del && ci > word.length) { del = true; setTimeout(typeLoop, 1200); return; }
if (del && ci < 0) { del = false; wi = (wi + 1) % words.length; ci = 0; }
setTimeout(typeLoop, del ? 50 : 90);
}
typeLoop();
// ─── Particle Canvas ──────────────────────────────────────
const canvas = document.getElementById('particleCanvas');
const ctx = canvas.getContext('2d');
let particles = [];
function resizeCanvas() { canvas.width = window.innerWidth; canvas.height = window.innerHeight; }
resizeCanvas();
window.addEventListener('resize', resizeCanvas);
function Particle() {
this.x = Math.random() * canvas.width;
this.y = Math.random() * canvas.height;
this.r = Math.random() * 2 + 0.5;
this.vx = (Math.random() - 0.5) * 0.4;
this.vy = (Math.random() - 0.5) * 0.4;
this.alpha = Math.random() * 0.6 + 0.1;
}
for (let i = 0; i < 120; i++) particles.push(new Particle());
function drawParticles() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
particles.forEach(p => {
ctx.beginPath();
ctx.arc(p.x, p.y, p.r, 0, Math.PI * 2);
ctx.fillStyle = `rgba(59,130,246,${p.alpha})`;
ctx.fill();
p.x += p.vx; p.y += p.vy;
if (p.x < 0 || p.x > canvas.width) p.vx *= -1;
if (p.y < 0 || p.y > canvas.height) p.vy *= -1;
});
// Lines
particles.forEach((a, i) => {
particles.slice(i + 1).forEach(b => {
const d = Math.hypot(a.x - b.x, a.y - b.y);
if (d < 120) {
ctx.beginPath();
ctx.moveTo(a.x, a.y); ctx.lineTo(b.x, b.y);
ctx.strokeStyle = `rgba(59,130,246,${0.15 * (1 - d / 120)})`;
ctx.lineWidth = 0.5;
ctx.stroke();
}
});
});
requestAnimationFrame(drawParticles);
}
drawParticles();
// ─── Stat Counter ─────────────────────────────────────────
function animateCount(el, target, isFloat) {
let cur = 0, step = target / 60;
const timer = setInterval(() => {
cur = Math.min(cur + step, target);
el.textContent = isFloat ? cur.toFixed(2) : Math.floor(cur) + '+';
if (cur >= target) { el.textContent = isFloat ? target : target + '+'; clearInterval(timer); }
}, 25);
}
const statsObs = new IntersectionObserver(entries => {
entries.forEach(e => {
if (e.isIntersecting) {
e.target.querySelectorAll('.stat-num').forEach(el => {
const val = parseFloat(el.dataset.count);
animateCount(el, val, el.dataset.count.includes('.'));
});
statsObs.unobserve(e.target);
}
});
}, { threshold: 0.5 });
const heroStats = document.querySelector('.hero-stats');
if (heroStats) statsObs.observe(heroStats);
// ─── Reveal on Scroll ─────────────────────────────────────
const revealObs = new IntersectionObserver(entries => {
entries.forEach(e => {
if (e.isIntersecting) {
const delay = e.target.style.getPropertyValue('--delay') || '0s';
setTimeout(() => e.target.classList.add('visible'), parseFloat(delay) * 1000);
}
});
}, { threshold: 0.15 });
document.querySelectorAll('.reveal-up,.reveal-left,.reveal-right').forEach(el => revealObs.observe(el));
// ─── Back To Top ──────────────────────────────────────────
document.getElementById('backToTop').addEventListener('click', () => window.scrollTo({ top: 0, behavior: 'smooth' }));
// ─── Contact Form ─────────────────────────────────────────
document.getElementById('contactForm').addEventListener('submit', e => {
e.preventDefault();
const name = document.getElementById('contactName').value;
const email = document.getElementById('contactEmail').value;
const msg = document.getElementById('contactMsg').value;
const note = document.getElementById('formNote');
const mailto = `https://mail.google.com/mail/?view=cm&fs=1&to=ruchakatte@gmail.com&su=Portfolio Contact from ${encodeURIComponent(name)}&body=${encodeURIComponent(msg + '\n\nFrom: ' + name + ' <' + email + '>')}`;
window.open(mailto, '_blank');
note.textContent = '✅ Opening Gmail to send your message!';
e.target.reset();
setTimeout(() => note.textContent = '', 4000);
});
// ─── Resume Download ──────────────────────────────────────
// Download is handled natively via the HTML `download` attribute on the link.