-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
347 lines (298 loc) ยท 12.9 KB
/
script.js
File metadata and controls
347 lines (298 loc) ยท 12.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
// Steam Portfolio JavaScript - Single Page Version with Separated Sections
// Performance-optimized IntersectionObserver for animations
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const animationObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('animate-in');
animationObserver.unobserve(entry.target);
}
});
}, observerOptions);
// Navigation active state observer - More reliable approach
let scrollTimeout;
function updateNavOnScroll() {
if (scrollTimeout) {
window.cancelAnimationFrame(scrollTimeout);
}
scrollTimeout = window.requestAnimationFrame(() => {
const sections = document.querySelectorAll('.section-card');
const navLinks = document.querySelectorAll('.nav-link');
let currentSection = 'home'; // default
const scrollPos = window.scrollY + window.innerHeight / 3; // Check at 1/3 from top
sections.forEach(section => {
const sectionTop = section.offsetTop;
const sectionBottom = sectionTop + section.offsetHeight;
if (scrollPos >= sectionTop && scrollPos < sectionBottom) {
currentSection = section.getAttribute('id');
}
});
navLinks.forEach(link => {
link.classList.remove('active');
const href = link.getAttribute('href');
if (href === `#${currentSection}`) {
link.classList.add('active');
}
});
});
}
// Wait for DOM to load
document.addEventListener('DOMContentLoaded', function() {
// Set up scroll spy for navigation
window.addEventListener('scroll', updateNavOnScroll);
updateNavOnScroll(); // Run once on load
// Smooth scroll for navigation links
document.querySelectorAll('.nav-link').forEach(link => {
link.addEventListener('click', function(e) {
e.preventDefault();
const targetId = this.getAttribute('href').substring(1);
const targetSection = document.getElementById(targetId);
if (targetSection) {
targetSection.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
// Counter Animation for Stats
const counters = document.querySelectorAll('.counter');
if (counters.length > 0) {
const speed = 200;
// Create an observer for counters
const counterObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const counter = entry.target;
const animate = () => {
const value = +counter.getAttribute('data-target');
const data = +counter.innerText;
const time = value / speed;
if(data < value) {
counter.innerText = Math.ceil(data + time);
setTimeout(animate, 10);
} else {
if (counter.parentElement.querySelector('.stat-label').textContent.includes('K+')) {
counter.innerText = value + 'K+';
} else if (counter.parentElement.querySelector('.stat-label').textContent.includes('%')) {
counter.innerText = value + '%';
} else {
counter.innerText = value + '+';
}
}
}
setTimeout(animate, 500);
counterObserver.unobserve(counter);
}
});
}, { threshold: 0.5 });
counters.forEach(counter => {
counterObserver.observe(counter);
});
}
// Glitch effect on name and section titles
const glitchElements = document.querySelectorAll('.glitch');
glitchElements.forEach(element => {
element.addEventListener('mouseenter', function() {
this.classList.add('glitch-active');
setTimeout(() => {
this.classList.remove('glitch-active');
}, 500);
});
});
// Achievement hover animations
const achievements = document.querySelectorAll('.achievement');
achievements.forEach(ach => {
ach.addEventListener('mouseenter', function() {
if(!this.classList.contains('locked')) {
this.style.transform = 'scale(1.2) rotate(5deg)';
setTimeout(() => {
this.style.transform = 'scale(1) rotate(0deg)';
}, 200);
}
});
});
// Project filters
const filters = document.querySelectorAll('.filter-tag');
const projects = document.querySelectorAll('#projects .project-card');
filters.forEach(filter => {
filter.addEventListener('click', function() {
// Update active filter
filters.forEach(f => f.classList.remove('active'));
this.classList.add('active');
const filterValue = this.getAttribute('data-filter');
// Animate filter change
projects.forEach(project => {
project.style.transform = 'scale(0.9)';
project.style.opacity = '0.5';
setTimeout(() => {
// Filter logic
if (filterValue === 'all') {
project.style.display = 'block';
} else {
const category = project.getAttribute('data-category');
const normalizedCategory = category ? category.toLowerCase().replace(/[\s\/]/g, '') : '';
const normalizedFilter = filterValue.toLowerCase().replace(/[\s\/]/g, '');
if (normalizedCategory.includes(normalizedFilter)) {
project.style.display = 'block';
} else {
project.style.display = 'none';
}
}
project.style.transform = 'scale(1)';
project.style.opacity = '1';
}, 300);
});
});
});
// Project card hover effects
const allProjectCards = document.querySelectorAll('.project-card');
allProjectCards.forEach(project => {
project.addEventListener('mouseenter', function() {
const icon = this.querySelector('.project-icon');
if (icon) {
icon.style.animation = 'icon-bounce 0.5s ease';
setTimeout(() => {
icon.style.animation = 'project-icon-glow 2s ease-in-out infinite';
}, 500);
}
});
});
// Add parallax effect to particles with throttling for better performance
let ticking = false;
document.addEventListener('mousemove', function(e) {
if (!ticking) {
window.requestAnimationFrame(() => {
const particles = document.querySelector('.particles');
if (particles) {
const x = e.clientX / window.innerWidth;
const y = e.clientY / window.innerHeight;
particles.style.transform = `translate(${x * 20}px, ${y * 20}px)`;
}
ticking = false;
});
ticking = true;
}
});
// Add sound effect simulation on button clicks (visual feedback)
const buttons = document.querySelectorAll('.steam-btn, .project-link');
buttons.forEach(button => {
button.addEventListener('click', function(e) {
// Create ripple effect
const ripple = document.createElement('span');
ripple.classList.add('click-ripple');
const rect = this.getBoundingClientRect();
const size = Math.max(rect.width, rect.height);
const x = e.clientX - rect.left - size / 2;
const y = e.clientY - rect.top - size / 2;
ripple.style.width = ripple.style.height = size + 'px';
ripple.style.left = x + 'px';
ripple.style.top = y + 'px';
this.appendChild(ripple);
setTimeout(() => {
ripple.remove();
}, 600);
});
});
// Add Easter egg - Konami code
let konamiCode = ['ArrowUp', 'ArrowUp', 'ArrowDown', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'ArrowLeft', 'ArrowRight', 'b', 'a'];
let konamiIndex = 0;
document.addEventListener('keydown', function(e) {
if (e.key === konamiCode[konamiIndex]) {
konamiIndex++;
if (konamiIndex === konamiCode.length) {
activateEasterEgg();
konamiIndex = 0;
}
} else {
konamiIndex = 0;
}
});
function activateEasterEgg() {
// Create achievement notification
const notification = document.createElement('div');
notification.className = 'easter-egg-notification';
notification.innerHTML = `
<span class="achievement-icon">๐ฎ</span>
<span>Secret Achievement Unlocked: Konami Master!</span>
`;
document.body.appendChild(notification);
// Trigger rainbow effect
document.body.classList.add('rainbow-mode');
setTimeout(() => {
notification.remove();
document.body.classList.remove('rainbow-mode');
}, 5000);
}
// Reveal animations on scroll
const revealElements = document.querySelectorAll('.project-card, .skill-category, .social-link');
const revealObserver = new IntersectionObserver((entries) => {
entries.forEach((entry, index) => {
if (entry.isIntersecting) {
setTimeout(() => {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}, index * 100);
revealObserver.unobserve(entry.target);
}
});
}, { threshold: 0.1 });
revealElements.forEach(el => {
el.style.opacity = '0';
el.style.transform = 'translateY(30px)';
el.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
revealObserver.observe(el);
});
// Add typing effect to bio (only on first visit to home section)
const bio = document.querySelector('.bio');
if (bio && !sessionStorage.getItem('bioAnimated')) {
const text = bio.textContent;
bio.textContent = '';
bio.style.visibility = 'visible';
let index = 0;
function typeWriter() {
if (index < text.length) {
bio.textContent += text.charAt(index);
index++;
setTimeout(typeWriter, 20);
}
}
setTimeout(typeWriter, 1000);
sessionStorage.setItem('bioAnimated', 'true');
}
// Keyboard navigation for sections
document.addEventListener('keydown', function(e) {
// Ignore if typing in an input
if (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA') {
return;
}
const sections = ['home', 'experience', 'education', 'projects', 'skills', 'connect'];
const currentActive = document.querySelector('.nav-link.active');
if (!currentActive) return;
const currentHref = currentActive.getAttribute('href').substring(1);
const currentIndex = sections.indexOf(currentHref);
if (e.key === 'ArrowDown' && currentIndex < sections.length - 1) {
e.preventDefault();
const nextSection = document.getElementById(sections[currentIndex + 1]);
if (nextSection) {
nextSection.scrollIntoView({ behavior: 'smooth', block: 'start' });
}
} else if (e.key === 'ArrowUp' && currentIndex > 0) {
e.preventDefault();
const prevSection = document.getElementById(sections[currentIndex - 1]);
if (prevSection) {
prevSection.scrollIntoView({ behavior: 'smooth', block: 'start' });
}
}
});
});
// Console Easter Egg
console.log('%c๐ฎ Welcome to the Steam Portfolio! ๐ฎ',
'font-size: 20px; font-weight: bold; color: #66c0f4; text-shadow: 0 0 10px #66c0f4;');
console.log('%cPress โ โ โ โ โ โ โ โ B A for a surprise!',
'font-size: 12px; color: #a4d007;');
console.log('%cUse โ and โ arrow keys to navigate between sections',
'font-size: 11px; color: #8f98a0;');