-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
356 lines (309 loc) · 12 KB
/
script.js
File metadata and controls
356 lines (309 loc) · 12 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
// DOM Content Loaded
document.addEventListener('DOMContentLoaded', function() {
// Initialize all components
initNavigation();
initScrollEffects();
initAnimations();
initMobileMenu();
initSmoothScrolling();
});
// Navigation functionality
function initNavigation() {
const navbar = document.getElementById('navbar');
const navLinks = document.querySelectorAll('.nav-link');
// Navbar scroll effect
window.addEventListener('scroll', () => {
if (window.scrollY > 100) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
});
// Active link highlighting
window.addEventListener('scroll', () => {
let current = '';
const sections = document.querySelectorAll('section[id]');
sections.forEach(section => {
const sectionTop = section.offsetTop;
const sectionHeight = section.clientHeight;
if (window.scrollY >= (sectionTop - 200)) {
current = section.getAttribute('id');
}
});
navLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === `#${current}`) {
link.classList.add('active');
}
});
});
}
// Mobile menu functionality
function initMobileMenu() {
const mobileMenu = document.getElementById('mobile-menu');
const navMenu = document.getElementById('nav-menu');
const navLinks = document.querySelectorAll('.nav-link');
// Toggle mobile menu
mobileMenu.addEventListener('click', () => {
mobileMenu.classList.toggle('active');
navMenu.classList.toggle('active');
// Prevent body scroll when menu is open
document.body.style.overflow = navMenu.classList.contains('active') ? 'hidden' : 'auto';
});
// Close mobile menu when clicking on a link
navLinks.forEach(link => {
link.addEventListener('click', () => {
mobileMenu.classList.remove('active');
navMenu.classList.remove('active');
document.body.style.overflow = 'auto';
});
});
// Close mobile menu when clicking outside
document.addEventListener('click', (e) => {
if (!navMenu.contains(e.target) && !mobileMenu.contains(e.target)) {
mobileMenu.classList.remove('active');
navMenu.classList.remove('active');
document.body.style.overflow = 'auto';
}
});
}
// Smooth scrolling for navigation links
function initSmoothScrolling() {
const navLinks = document.querySelectorAll('.nav-link, .btn[href^="#"]');
navLinks.forEach(link => {
link.addEventListener('click', (e) => {
e.preventDefault();
const targetId = link.getAttribute('href');
const targetSection = document.querySelector(targetId);
if (targetSection) {
const offsetTop = targetSection.offsetTop - 80; // Account for fixed navbar
window.scrollTo({
top: offsetTop,
behavior: 'smooth'
});
}
});
});
}
// Scroll animations and effects
function initScrollEffects() {
// Intersection Observer for fade-in animations
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('animate-in');
}
});
}, observerOptions);
// Observe elements for animation
const animateElements = document.querySelectorAll(
'.skill-category, .project-card, .highlight-item, .expertise-item, .learning-item, .contact-method'
);
animateElements.forEach(el => {
el.classList.add('animate-on-scroll');
observer.observe(el);
});
}
// Initialize animations
function initAnimations() {
// Add CSS for scroll animations
const style = document.createElement('style');
style.textContent = `
.animate-on-scroll {
opacity: 0;
transform: translateY(30px);
transition: opacity 0.6s ease, transform 0.6s ease;
}
.animate-on-scroll.animate-in {
opacity: 1;
transform: translateY(0);
}
/* Stagger animation for grid items */
.skills-grid .skill-category:nth-child(1) { transition-delay: 0.1s; }
.skills-grid .skill-category:nth-child(2) { transition-delay: 0.2s; }
.skills-grid .skill-category:nth-child(3) { transition-delay: 0.3s; }
.projects-grid .project-card:nth-child(1) { transition-delay: 0.1s; }
.projects-grid .project-card:nth-child(2) { transition-delay: 0.2s; }
.projects-grid .project-card:nth-child(3) { transition-delay: 0.3s; }
.about-highlights .highlight-item:nth-child(1) { transition-delay: 0.1s; }
.about-highlights .highlight-item:nth-child(2) { transition-delay: 0.2s; }
.about-highlights .highlight-item:nth-child(3) { transition-delay: 0.3s; }
.expertise-areas .expertise-item:nth-child(1) { transition-delay: 0.1s; }
.expertise-areas .expertise-item:nth-child(2) { transition-delay: 0.2s; }
.expertise-areas .expertise-item:nth-child(3) { transition-delay: 0.3s; }
.expertise-areas .expertise-item:nth-child(4) { transition-delay: 0.4s; }
.learning-items .learning-item:nth-child(1) { transition-delay: 0.1s; }
.learning-items .learning-item:nth-child(2) { transition-delay: 0.2s; }
.learning-items .learning-item:nth-child(3) { transition-delay: 0.3s; }
.contact-methods .contact-method:nth-child(1) { transition-delay: 0.1s; }
.contact-methods .contact-method:nth-child(2) { transition-delay: 0.2s; }
.contact-methods .contact-method:nth-child(3) { transition-delay: 0.3s; }
.contact-methods .contact-method:nth-child(4) { transition-delay: 0.4s; }
`;
document.head.appendChild(style);
}
// Typing animation for hero section
function initTypingAnimation() {
const subtitle = document.querySelector('.hero-subtitle');
if (subtitle) {
const text = subtitle.textContent;
subtitle.textContent = '';
subtitle.style.borderRight = '2px solid var(--primary-color)';
let i = 0;
const typeWriter = () => {
if (i < text.length) {
subtitle.textContent += text.charAt(i);
i++;
setTimeout(typeWriter, 100);
} else {
// Remove cursor after typing is complete
setTimeout(() => {
subtitle.style.borderRight = 'none';
}, 1000);
}
};
// Start typing animation after a delay
setTimeout(typeWriter, 1000);
}
}
// Parallax effect for hero section
function initParallax() {
window.addEventListener('scroll', () => {
const scrolled = window.pageYOffset;
const hero = document.querySelector('.hero');
if (hero) {
const rate = scrolled * -0.5;
hero.style.transform = `translateY(${rate}px)`;
}
});
}
// Stats counter animation
function initStatsCounter() {
const stats = document.querySelectorAll('.stat-number');
const observerOptions = {
threshold: 0.5
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const target = entry.target;
const text = target.textContent;
const number = parseInt(text.replace(/\D/g, ''));
if (number && !target.classList.contains('counted')) {
target.classList.add('counted');
animateCounter(target, number, text);
}
}
});
}, observerOptions);
stats.forEach(stat => observer.observe(stat));
}
// Counter animation function
function animateCounter(element, target, originalText) {
let current = 0;
const increment = target / 30;
const timer = setInterval(() => {
current += increment;
if (current >= target) {
element.textContent = originalText;
clearInterval(timer);
} else {
element.textContent = Math.floor(current) + '+';
}
}, 50);
}
// Email obfuscation (basic protection)
function obfuscateEmail() {
const emailLinks = document.querySelectorAll('a[href*="mailto:"]');
emailLinks.forEach(link => {
const email = link.href.replace('mailto:', '');
link.href = `mailto:${email}`;
link.addEventListener('click', (e) => {
// Track email click event (if analytics is implemented)
console.log('Email contact initiated');
});
});
}
// Keyboard navigation support
function initKeyboardNavigation() {
document.addEventListener('keydown', (e) => {
// ESC key closes mobile menu
if (e.key === 'Escape') {
const mobileMenu = document.getElementById('mobile-menu');
const navMenu = document.getElementById('nav-menu');
if (navMenu.classList.contains('active')) {
mobileMenu.classList.remove('active');
navMenu.classList.remove('active');
document.body.style.overflow = 'auto';
}
}
});
}
// Performance optimization: Lazy load images (if any are added later)
function initLazyLoading() {
if ('IntersectionObserver' in window) {
const imageObserver = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const img = entry.target;
img.src = img.dataset.src;
img.classList.remove('lazy');
imageObserver.unobserve(img);
}
});
});
const lazyImages = document.querySelectorAll('img[data-src]');
lazyImages.forEach(img => imageObserver.observe(img));
}
}
// Error handling for external links
function initExternalLinks() {
const externalLinks = document.querySelectorAll('a[target="_blank"]');
externalLinks.forEach(link => {
link.addEventListener('click', (e) => {
// Add rel="noopener noreferrer" for security
link.rel = 'noopener noreferrer';
// Track external link clicks (if analytics is implemented)
console.log('External link clicked:', link.href);
});
});
}
// Initialize additional features when DOM is ready
document.addEventListener('DOMContentLoaded', function() {
// Add additional initializations
setTimeout(() => {
initStatsCounter();
initTypingAnimation();
obfuscateEmail();
initKeyboardNavigation();
initLazyLoading();
initExternalLinks();
}, 100);
});
// Performance monitoring
window.addEventListener('load', () => {
// Log page load time for performance monitoring
const loadTime = performance.now();
console.log(`Page loaded in ${Math.round(loadTime)}ms`);
// Optional: Send to analytics service
// analytics.track('page_load_time', { time: loadTime });
});
// Error handling
window.addEventListener('error', (e) => {
console.error('JavaScript error:', e.error);
// Optional: Send to error tracking service
// errorTracking.log(e.error);
});
// Service Worker registration (for future PWA features)
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
// Uncomment when service worker is implemented
// navigator.serviceWorker.register('/sw.js')
// .then(registration => console.log('SW registered'))
// .catch(error => console.log('SW registration failed'));
});
}