-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
267 lines (230 loc) · 7.79 KB
/
script.js
File metadata and controls
267 lines (230 loc) · 7.79 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
/* ═══════════════════════════════════════════════════
Q's Build Lab — Portfolio Scripts
═══════════════════════════════════════════════════ */
(function () {
'use strict';
/* ── Typing Animation ────────────────────────── */
const phrases = [
'building biotech tools...',
'tracking longevity research...',
'scanning deal flow...',
'calculating biological age...',
'aggregating sector signals...',
'shipping pure python...',
];
const typingEl = document.getElementById('typing');
let phraseIdx = 0;
let charIdx = 0;
let deleting = false;
let pauseMs = 0;
function typeLoop() {
const current = phrases[phraseIdx];
if (pauseMs > 0) {
pauseMs = 0;
setTimeout(typeLoop, 1600);
return;
}
if (!deleting) {
typingEl.textContent = current.slice(0, charIdx + 1);
charIdx++;
if (charIdx >= current.length) {
deleting = true;
pauseMs = 1;
setTimeout(typeLoop, 50);
return;
}
setTimeout(typeLoop, 45 + Math.random() * 35);
} else {
typingEl.textContent = current.slice(0, charIdx);
charIdx--;
if (charIdx < 0) {
deleting = false;
charIdx = 0;
phraseIdx = (phraseIdx + 1) % phrases.length;
setTimeout(typeLoop, 300);
return;
}
setTimeout(typeLoop, 20 + Math.random() * 15);
}
}
if (typingEl) typeLoop();
/* ── Counter Animation ───────────────────────── */
function animateCounters() {
const counters = document.querySelectorAll('.stat-num');
counters.forEach(el => {
const target = parseInt(el.dataset.target, 10);
const duration = 1800;
const start = performance.now();
function step(now) {
const elapsed = now - start;
const progress = Math.min(elapsed / duration, 1);
// ease out quart
const eased = 1 - Math.pow(1 - progress, 4);
const current = Math.round(eased * target);
if (target === 0) {
el.textContent = '0';
} else {
el.textContent = current.toLocaleString();
}
if (progress < 1) {
requestAnimationFrame(step);
}
}
requestAnimationFrame(step);
});
}
/* ── Scroll Animations (IntersectionObserver) ── */
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -40px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
observer.unobserve(entry.target);
}
});
}, observerOptions);
document.querySelectorAll('.card, .stack-item, .about-content, .philosophy').forEach(el => {
observer.observe(el);
});
/* ── Hero stats counter trigger ──────────────── */
const statsSection = document.querySelector('.hero-stats');
if (statsSection) {
const statsObserver = new IntersectionObserver((entries) => {
if (entries[0].isIntersecting) {
animateCounters();
statsObserver.disconnect();
}
}, { threshold: 0.5 });
statsObserver.observe(statsSection);
}
/* ── Nav scroll styling ──────────────────────── */
const nav = document.getElementById('nav');
let ticking = false;
function onScroll() {
if (!ticking) {
requestAnimationFrame(() => {
if (window.scrollY > 60) {
nav.classList.add('scrolled');
} else {
nav.classList.remove('scrolled');
}
ticking = false;
});
ticking = true;
}
}
window.addEventListener('scroll', onScroll, { passive: true });
/* ── Mobile nav toggle ───────────────────────── */
const navToggle = document.getElementById('nav-toggle');
const navLinks = document.querySelector('.nav-links');
if (navToggle && navLinks) {
navToggle.addEventListener('click', () => {
navLinks.classList.toggle('open');
});
navLinks.querySelectorAll('a').forEach(link => {
link.addEventListener('click', () => {
navLinks.classList.remove('open');
});
});
}
/* ── Particles ───────────────────────────────── */
const canvas = document.getElementById('particles');
if (canvas) {
const ctx = canvas.getContext('2d');
let width, height;
let particles = [];
const PARTICLE_COUNT = 40;
const prefersReduced = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
function resize() {
width = canvas.width = window.innerWidth;
height = canvas.height = window.innerHeight;
}
function createParticle() {
return {
x: Math.random() * width,
y: Math.random() * height,
vx: (Math.random() - 0.5) * 0.3,
vy: (Math.random() - 0.5) * 0.3,
size: Math.random() * 1.5 + 0.5,
alpha: Math.random() * 0.4 + 0.1,
};
}
function init() {
resize();
particles = [];
for (let i = 0; i < PARTICLE_COUNT; i++) {
particles.push(createParticle());
}
}
function draw() {
ctx.clearRect(0, 0, width, height);
particles.forEach(p => {
p.x += p.vx;
p.y += p.vy;
if (p.x < 0) p.x = width;
if (p.x > width) p.x = 0;
if (p.y < 0) p.y = height;
if (p.y > height) p.y = 0;
ctx.beginPath();
ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
ctx.fillStyle = `rgba(0, 229, 191, ${p.alpha})`;
ctx.fill();
});
// Draw lines between nearby particles
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 < 150) {
const alpha = (1 - dist / 150) * 0.08;
ctx.beginPath();
ctx.moveTo(particles[i].x, particles[i].y);
ctx.lineTo(particles[j].x, particles[j].y);
ctx.strokeStyle = `rgba(0, 229, 191, ${alpha})`;
ctx.lineWidth = 0.5;
ctx.stroke();
}
}
}
if (!prefersReduced) {
requestAnimationFrame(draw);
}
}
init();
if (!prefersReduced) {
draw();
} else {
// Draw once for static particles
draw();
}
window.addEventListener('resize', () => {
resize();
});
}
/* ── Make entire card clickable ────────────────── */
document.querySelectorAll('.card').forEach(card => {
card.addEventListener('click', function (e) {
// Don't hijack if user clicked an actual link inside the card
if (e.target.closest('a')) return;
const link = card.querySelector('.card-title a') || card.querySelector('.card-link');
if (link) {
window.open(link.href, '_blank', 'noopener');
}
});
});
/* ── Smooth scroll for anchor links ──────────── */
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
const target = document.querySelector(this.getAttribute('href'));
if (target) {
e.preventDefault();
const top = target.getBoundingClientRect().top + window.pageYOffset - 80;
window.scrollTo({ top, behavior: 'smooth' });
}
});
});
})();