-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
486 lines (412 loc) · 15.2 KB
/
script.js
File metadata and controls
486 lines (412 loc) · 15.2 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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
// Professional Portfolio JavaScript
document.addEventListener('DOMContentLoaded', function() {
// Initialize all functionality
initializeNavigation();
initializeAnimations();
initializeSkillBars();
initializeTypingEffect();
initializeMobileMenu();
initializeScrollEffects();
});
// Navigation functionality
function initializeNavigation() {
const navbar = document.querySelector('.navbar');
const navLinks = document.querySelectorAll('.nav-menu a');
// Smooth scrolling for navigation links
navLinks.forEach(link => {
link.addEventListener('click', function(e) {
e.preventDefault();
const targetId = this.getAttribute('href').substring(1);
const targetSection = document.getElementById(targetId);
if (targetSection) {
const offsetTop = targetSection.offsetTop - navbar.offsetHeight;
window.scrollTo({
top: offsetTop,
behavior: 'smooth'
});
}
});
});
// Navbar background change on scroll
window.addEventListener('scroll', function() {
if (window.scrollY > 50) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
});
// Active navigation highlighting
window.addEventListener('scroll', function() {
const sections = document.querySelectorAll('section[id]');
const scrollPosition = window.scrollY + navbar.offsetHeight + 50;
sections.forEach(section => {
const sectionTop = section.offsetTop;
const sectionHeight = section.offsetHeight;
const sectionId = section.getAttribute('id');
const navLink = document.querySelector(`.nav-menu a[href="#${sectionId}"]`);
if (scrollPosition >= sectionTop && scrollPosition < sectionTop + sectionHeight) {
navLinks.forEach(link => link.classList.remove('active'));
if (navLink) {
navLink.classList.add('active');
}
}
});
});
}
// Mobile menu functionality
function initializeMobileMenu() {
const hamburger = document.querySelector('.hamburger');
const navMenu = document.querySelector('.nav-menu');
const navLinks = document.querySelectorAll('.nav-menu a');
const body = document.body;
function toggleMenu() {
hamburger.classList.toggle('active');
navMenu.classList.toggle('active');
// Prevent body scroll when menu is open
body.style.overflow = navMenu.classList.contains('active') ? 'hidden' : '';
}
function closeMenu() {
hamburger.classList.remove('active');
navMenu.classList.remove('active');
body.style.overflow = '';
}
hamburger.addEventListener('click', function(e) {
e.stopPropagation();
toggleMenu();
});
// Close mobile menu when clicking on a link
navLinks.forEach(link => {
link.addEventListener('click', function() {
closeMenu();
});
});
// Close mobile menu when clicking outside
document.addEventListener('click', function(e) {
if (!hamburger.contains(e.target) && !navMenu.contains(e.target)) {
closeMenu();
}
});
// Close menu on escape key
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape' && navMenu.classList.contains('active')) {
closeMenu();
}
});
// Close menu on window resize to desktop
window.addEventListener('resize', function() {
if (window.innerWidth > 768) {
closeMenu();
}
});
}
// Scroll-triggered animations
function initializeAnimations() {
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver(function(entries) {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
}
});
}, observerOptions);
// Observe elements for animations
const animatedElements = document.querySelectorAll('.fade-in, .slide-in-left, .slide-in-right');
animatedElements.forEach(element => {
observer.observe(element);
});
// Add animation classes to elements
document.querySelectorAll('.app-card').forEach((card, index) => {
card.classList.add('fade-in');
card.style.animationDelay = `${index * 0.2}s`;
});
document.querySelectorAll('.timeline-item').forEach((item, index) => {
if (index % 2 === 0) {
item.classList.add('slide-in-left');
} else {
item.classList.add('slide-in-right');
}
item.style.animationDelay = `${index * 0.3}s`;
});
document.querySelectorAll('.skill-category').forEach((category, index) => {
category.classList.add('fade-in');
category.style.animationDelay = `${index * 0.2}s`;
});
document.querySelectorAll('.award-item').forEach((award, index) => {
award.classList.add('fade-in');
award.style.animationDelay = `${index * 0.1}s`;
});
}
// Skill bars animation
function initializeSkillBars() {
const skillObserver = new IntersectionObserver(function(entries) {
entries.forEach(entry => {
if (entry.isIntersecting) {
const skillBars = entry.target.querySelectorAll('.skill-progress');
skillBars.forEach(bar => {
const width = bar.getAttribute('data-width');
setTimeout(() => {
bar.style.width = width + '%';
}, 500);
});
}
});
}, { threshold: 0.5 });
document.querySelectorAll('.skills').forEach(section => {
skillObserver.observe(section);
});
}
// Typing effect for hero section
function initializeTypingEffect() {
const heroSubtitle = document.querySelector('.hero-subtitle');
if (!heroSubtitle) return;
const texts = [
'Data Scientist & iOS Developer',
'MBA at Hitotsubashi University, Tokyo',
'MEXT Young Leaders’ Program Scholar',
'Technology Professional'
];
let textIndex = 0;
let charIndex = 0;
let isDeleting = false;
function typeWriter() {
const currentText = texts[textIndex];
if (isDeleting) {
heroSubtitle.textContent = currentText.substring(0, charIndex - 1);
charIndex--;
} else {
heroSubtitle.textContent = currentText.substring(0, charIndex + 1);
charIndex++;
}
// Use invisible character to prevent layout shift when text is empty
if (heroSubtitle.textContent === '') {
heroSubtitle.innerHTML = ' '; // Non-breaking space maintains height
}
let speed = isDeleting ? 50 : 100;
if (!isDeleting && charIndex === currentText.length) {
speed = 2000; // Pause at end
isDeleting = true;
} else if (isDeleting && charIndex === 0) {
isDeleting = false;
textIndex = (textIndex + 1) % texts.length;
speed = 500; // Pause before next text
}
setTimeout(typeWriter, speed);
}
// Start typing effect after a delay
setTimeout(typeWriter, 1000);
}
// Scroll effects and parallax
function initializeScrollEffects() {
window.addEventListener('scroll', function() {
const scrolled = window.pageYOffset;
const parallaxElements = document.querySelectorAll('.hero');
parallaxElements.forEach(element => {
const speed = 0.5;
element.style.transform = `translateY(${scrolled * speed}px)`;
});
});
// Add scroll indicator
createScrollIndicator();
}
// Create scroll progress indicator
function createScrollIndicator() {
const scrollIndicator = document.createElement('div');
scrollIndicator.style.cssText = `
position: fixed;
top: 0;
left: 0;
width: 0%;
height: 3px;
background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
z-index: 9999;
transition: width 0.3s ease;
`;
document.body.appendChild(scrollIndicator);
window.addEventListener('scroll', function() {
const windowHeight = document.documentElement.scrollHeight - document.documentElement.clientHeight;
const scrolled = (window.scrollY / windowHeight) * 100;
scrollIndicator.style.width = scrolled + '%';
});
}
// Smooth reveal animations for sections
function initializeScrollReveal() {
const sections = document.querySelectorAll('section');
const revealSection = function(entries, observer) {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('section-visible');
// Optional: Stop observing once revealed
// observer.unobserve(entry.target);
}
});
};
const sectionObserver = new IntersectionObserver(revealSection, {
root: null,
threshold: 0.15,
});
sections.forEach(section => {
section.classList.add('section-hidden');
sectionObserver.observe(section);
});
}
// Add interactive hover effects for app cards
function initializeAppCardEffects() {
const appCards = document.querySelectorAll('.app-card');
appCards.forEach(card => {
card.addEventListener('mouseenter', function() {
this.style.transform = 'translateY(-12px) scale(1.02)';
});
card.addEventListener('mouseleave', function() {
this.style.transform = 'translateY(0) scale(1)';
});
});
}
// Initialize contact form functionality (if needed)
function initializeContactForm() {
const contactLinks = document.querySelectorAll('.contact-link');
contactLinks.forEach(link => {
link.addEventListener('click', function(e) {
// Add analytics tracking or other functionality here
console.log('Contact link clicked:', this.textContent.trim());
});
});
}
// Add custom cursor effect (optional enhancement)
function initializeCustomCursor() {
const cursor = document.createElement('div');
cursor.classList.add('custom-cursor');
cursor.style.cssText = `
position: fixed;
width: 20px;
height: 20px;
border-radius: 50%;
background: var(--primary-color);
pointer-events: none;
z-index: 9999;
mix-blend-mode: difference;
transition: transform 0.15s ease;
opacity: 0;
`;
document.body.appendChild(cursor);
document.addEventListener('mousemove', function(e) {
cursor.style.left = e.clientX - 10 + 'px';
cursor.style.top = e.clientY - 10 + 'px';
cursor.style.opacity = '1';
});
document.addEventListener('mouseenter', function() {
cursor.style.opacity = '1';
});
document.addEventListener('mouseleave', function() {
cursor.style.opacity = '0';
});
// Scale cursor on hover for interactive elements
const interactiveElements = document.querySelectorAll('a, button, .app-card, .contact-link');
interactiveElements.forEach(element => {
element.addEventListener('mouseenter', function() {
cursor.style.transform = 'scale(1.5)';
});
element.addEventListener('mouseleave', function() {
cursor.style.transform = 'scale(1)';
});
});
}
// Performance optimization: Lazy loading for images (when added)
function initializeLazyLoading() {
const lazyImages = document.querySelectorAll('img[data-src]');
if ('IntersectionObserver' in window) {
const imageObserver = new IntersectionObserver(function(entries) {
entries.forEach(entry => {
if (entry.isIntersecting) {
const img = entry.target;
img.src = img.dataset.src;
img.classList.remove('lazy');
imageObserver.unobserve(img);
}
});
});
lazyImages.forEach(img => imageObserver.observe(img));
}
}
// Add dynamic year to footer
function updateFooterYear() {
const footerYear = document.querySelector('.footer p');
if (footerYear && footerYear.textContent.includes('2025')) {
const currentYear = new Date().getFullYear();
footerYear.textContent = footerYear.textContent.replace('2025', currentYear);
}
}
// Initialize app icon loading with fallback
function initializeAppIcons() {
const appIcons = document.querySelectorAll('.app-icon-image');
appIcons.forEach(icon => {
icon.addEventListener('error', function() {
// Create fallback icon element
const fallbackIcon = document.createElement('i');
fallbackIcon.className = 'fas fa-mobile-alt';
fallbackIcon.style.fontSize = '3rem';
fallbackIcon.style.marginBottom = 'var(--spacing-md)';
fallbackIcon.style.color = 'white';
// Replace failed image with fallback
this.parentNode.replaceChild(fallbackIcon, this);
});
// Add loading animation
icon.addEventListener('load', function() {
this.style.opacity = '1';
});
icon.style.opacity = '0';
icon.style.transition = 'opacity 0.3s ease';
});
}
// Call additional initialization functions
document.addEventListener('DOMContentLoaded', function() {
initializeScrollReveal();
initializeAppCardEffects();
initializeContactForm();
initializeAppIcons();
updateFooterYear();
// Optional: Enable custom cursor on desktop only
if (window.innerWidth > 768) {
// initializeCustomCursor(); // Uncomment to enable
}
});
// Additional CSS for section animations (mobile nav styles now in main CSS)
const additionalCSS = `
.nav-menu a.active {
color: var(--primary-color);
font-weight: 600;
}
.section-hidden {
opacity: 0;
transform: translateY(30px);
transition: all 0.6s ease;
}
.section-visible {
opacity: 1;
transform: translateY(0);
}
`;
// Inject additional CSS
const styleSheet = document.createElement('style');
styleSheet.textContent = additionalCSS;
document.head.appendChild(styleSheet);
// Add smooth page load animation (disabled to prevent flashing)
window.addEventListener('load', function() {
document.body.classList.add('loaded');
// Loading animation disabled to prevent content flashing
// const loadingCSS = `
// body {
// opacity: 0;
// transition: opacity 0.5s ease;
// }
//
// body.loaded {
// opacity: 1;
// }
// `;
// const loadingStyleSheet = document.createElement('style');
// loadingStyleSheet.textContent = loadingCSS;
// document.head.appendChild(loadingStyleSheet);
});