-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
374 lines (314 loc) · 12.8 KB
/
Copy pathscript.js
File metadata and controls
374 lines (314 loc) · 12.8 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
/* ==========================================
Main Script: Portfolio Interactions
========================================== */
document.addEventListener('DOMContentLoaded', () => {
// ------------------------------------------
// 0. Splash / Cover Screen
// ------------------------------------------
const splash = document.getElementById('splash');
const splashBtn = document.getElementById('splashBtn');
const splashTerminal = document.getElementById('splashTerminal');
const splashParticles = document.getElementById('splashParticles');
// Lock body scroll while splash is visible
document.body.classList.add('splash-active');
// Generate floating particles (Faster rise & quicker start)
for (let i = 0; i < 30; i++) {
const p = document.createElement('div');
p.classList.add('splash-particle');
p.style.left = Math.random() * 100 + '%';
p.style.animationDuration = (2 + Math.random() * 3) + 's';
p.style.animationDelay = Math.random() * 3 + 's';
p.style.width = (1 + Math.random() * 2) + 'px';
p.style.height = p.style.width;
splashParticles.appendChild(p);
}
// Generate portfolio floating particles (gentle float for main page)
const portfolioParticles = document.getElementById('portfolioParticles');
if (portfolioParticles) {
for (let i = 0; i < 40; i++) {
const p = document.createElement('div');
p.classList.add('portfolio-particle');
p.style.left = Math.random() * 100 + '%';
p.style.animationDuration = (6 + Math.random() * 8) + 's';
p.style.animationDelay = Math.random() * 8 + 's';
p.style.width = (1 + Math.random() * 2) + 'px';
p.style.height = p.style.width;
portfolioParticles.appendChild(p);
}
}
// --- Pre-render all prompt labels so they don't shift ---
const lines = splashTerminal.querySelectorAll('.splash-line');
lines.forEach(lineEl => {
const promptSpan = document.createElement('span');
promptSpan.className = 's-prompt';
promptSpan.textContent = lineEl.dataset.prompt;
const textSpan = document.createElement('span');
textSpan.className = 's-text';
lineEl.appendChild(promptSpan);
lineEl.appendChild(textSpan);
});
// --- Typewriter: type only the text part ---
function typewriterLine(lineEl, isLast = false) {
return new Promise(resolve => {
const text = lineEl.dataset.text;
const suffix = lineEl.dataset.suffix || '';
const suffixClass = lineEl.dataset.suffixClass || '';
const textSpan = lineEl.querySelector('.s-text');
// Add blinking cursor
const cursor = document.createElement('span');
cursor.className = 's-cursor';
lineEl.appendChild(cursor);
let i = 0;
const speed = 25;
function type() {
if (i < text.length) {
textSpan.textContent += text[i];
i++;
setTimeout(type, speed);
} else {
if (suffix) {
const suffixSpan = document.createElement('span');
suffixSpan.className = suffixClass;
suffixSpan.textContent = suffix;
textSpan.appendChild(suffixSpan);
}
if (!isLast) {
cursor.classList.add('done');
}
resolve();
}
}
type();
});
}
// Run boot lines sequentially with a small pause between each
async function runBootSequence() {
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
const isLast = (i === lines.length - 1);
await new Promise(r => setTimeout(r, 200));
await typewriterLine(line, isLast);
}
setTimeout(() => {
splashBtn.classList.add('show');
}, 400);
}
runBootSequence();
// --- Clean fade-out exit ---
splashBtn.addEventListener('click', () => {
splash.classList.add('exit');
document.body.classList.remove('splash-active');
setTimeout(() => {
splash.remove();
startRoleScramble();
}, 700);
});
// --- Scramble/Glitch Text Effect for Terminal Role ---
function scrambleText(element, targetWord, duration = 1200) {
return new Promise((resolve) => {
const chars = '!@#$%^&*()_+-=[]{}|;:,./<>?010101XYZ';
const startWord = element.textContent;
const startLen = startWord.length;
const targetLen = targetWord.length;
const startTime = performance.now();
element.classList.add('scrambling');
element.classList.remove('resolved');
function update(now) {
const elapsed = now - startTime;
const progress = Math.min(elapsed / duration, 1);
const freezeCount = Math.floor(progress * targetLen);
const currentLen = Math.round(startLen + (targetLen - startLen) * progress);
let result = '';
for (let i = 0; i < currentLen; i++) {
if (i < freezeCount) {
result += targetWord[i];
} else if (i < targetLen) {
result += chars[Math.floor(Math.random() * chars.length)];
} else {
if (Math.random() > progress) {
result += chars[Math.floor(Math.random() * chars.length)];
}
}
}
element.textContent = result;
if (progress < 1) {
requestAnimationFrame(update);
} else {
element.textContent = targetWord;
element.classList.remove('scrambling');
element.classList.add('resolved');
resolve();
}
}
requestAnimationFrame(update);
});
}
async function startRoleScramble() {
const roleWordEl = document.getElementById('terminal-role-word');
if (!roleWordEl) return;
// Start the scramble after 300ms delay to align with the terminal's fade-in animation
await new Promise(resolve => setTimeout(resolve, 300));
let currentWord = 'System';
while (true) {
await scrambleText(roleWordEl, currentWord, 1200);
// Wait for 2.5 seconds before scrambling back
await new Promise(resolve => setTimeout(resolve, 2500));
currentWord = (currentWord === 'System') ? 'Network' : 'System';
}
}
// ------------------------------------------
// 1. Typing Animation (Hero Section)
// ------------------------------------------
const roles = [
'System Engineer',
'Network Engineer',
'IT Admin & Support'
];
const typedEl = document.getElementById('typedText');
let roleIndex = 0;
let charIndex = 0;
let isDeleting = false;
function typeText() {
const current = roles[roleIndex];
if (isDeleting) {
typedEl.textContent = current.substring(0, charIndex - 1);
charIndex--;
} else {
typedEl.textContent = current.substring(0, charIndex + 1);
charIndex++;
}
let speed = isDeleting ? 40 : 80;
if (!isDeleting && charIndex === current.length) {
speed = 2000; // Pause at end
isDeleting = true;
} else if (isDeleting && charIndex === 0) {
isDeleting = false;
roleIndex = (roleIndex + 1) % roles.length;
speed = 500; // Pause before next word
}
setTimeout(typeText, speed);
}
typeText();
// ------------------------------------------
// 2. Cursor Glow Effect
// ------------------------------------------
const glow = document.getElementById('cursorGlow');
let mouseX = 0, mouseY = 0;
let glowX = 0, glowY = 0;
document.addEventListener('mousemove', (e) => {
mouseX = e.clientX;
mouseY = e.clientY;
glow.style.opacity = '1';
});
document.addEventListener('mouseleave', () => {
glow.style.opacity = '0';
});
function animateGlow() {
glowX += (mouseX - glowX) * 0.1;
glowY += (mouseY - glowY) * 0.1;
glow.style.left = glowX + 'px';
glow.style.top = glowY + 'px';
requestAnimationFrame(animateGlow);
}
animateGlow();
// ------------------------------------------
// 3. Navigation Scroll Effect
// ------------------------------------------
const nav = document.getElementById('nav');
window.addEventListener('scroll', () => {
if (window.scrollY > 50) {
nav.classList.add('scrolled');
} else {
nav.classList.remove('scrolled');
}
});
// ------------------------------------------
// 4. Mobile Menu Toggle
// ------------------------------------------
const navToggle = document.getElementById('navToggle');
const mobileMenu = document.getElementById('mobileMenu');
let menuOpen = false;
navToggle.addEventListener('click', () => {
menuOpen = !menuOpen;
mobileMenu.classList.toggle('open', menuOpen);
});
// Close mobile menu on link click
document.querySelectorAll('.mobile-link').forEach(link => {
link.addEventListener('click', () => {
menuOpen = false;
mobileMenu.classList.remove('open');
});
});
// ------------------------------------------
// 5. Scroll Reveal Animations
// ------------------------------------------
const revealElements = document.querySelectorAll('.reveal');
const revealObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const delay = entry.target.style.animationDelay || '0s';
const delayMs = parseFloat(delay) * 1000;
setTimeout(() => {
entry.target.classList.add('visible');
}, delayMs);
revealObserver.unobserve(entry.target);
}
});
}, { threshold: 0.1, rootMargin: '0px 0px -50px 0px' });
revealElements.forEach(el => revealObserver.observe(el));
// ------------------------------------------
// 6. Skill Bar Animations
// ------------------------------------------
const skillBars = document.querySelectorAll('.skill-fill');
const skillObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const width = entry.target.getAttribute('data-width');
entry.target.style.width = width + '%';
skillObserver.unobserve(entry.target);
}
});
}, { threshold: 0.3 });
skillBars.forEach(bar => skillObserver.observe(bar));
// ------------------------------------------
// 7. Counter Animation (Stats)
// ------------------------------------------
const statNumbers = document.querySelectorAll('.stat-number');
const counterObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const target = parseInt(entry.target.getAttribute('data-count'));
animateCounter(entry.target, target);
counterObserver.unobserve(entry.target);
}
});
}, { threshold: 0.5 });
statNumbers.forEach(el => counterObserver.observe(el));
function animateCounter(element, target) {
let current = 0;
const duration = 1500;
const step = target / (duration / 16);
function update() {
current += step;
if (current >= target) {
element.textContent = target;
return;
}
element.textContent = Math.floor(current);
requestAnimationFrame(update);
}
update();
}
// ------------------------------------------
// 8. Smooth Scroll for Anchor Links
// ------------------------------------------
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({ behavior: 'smooth' });
}
});
});
});