-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
429 lines (372 loc) · 13.2 KB
/
Copy pathscript.js
File metadata and controls
429 lines (372 loc) · 13.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
// DOM Content Loaded
document.addEventListener('DOMContentLoaded', function() {
// Initialize all functionality
initLoader();
initThemeToggle();
initMobileMenu();
initSmoothScrolling();
initScrollAnimations();
initNavbarScroll();
initTypingEffect();
initParticleEffect();
initContactForm();
});
// Loading Animation
function initLoader() {
const loader = document.querySelector('.loader');
if (loader) {
setTimeout(() => {
loader.classList.add('hidden');
setTimeout(() => {
loader.style.display = 'none';
}, 500);
}, 1500);
}
}
// Theme Toggle Functionality
function initThemeToggle() {
const themeToggle = document.querySelector('.theme-toggle');
const body = document.body;
// Check for saved theme preference or default to light mode
const savedTheme = localStorage.getItem('theme') || 'light';
body.setAttribute('data-theme', savedTheme);
updateThemeIcon(savedTheme);
if (themeToggle) {
themeToggle.addEventListener('click', () => {
const currentTheme = body.getAttribute('data-theme');
const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
body.setAttribute('data-theme', newTheme);
localStorage.setItem('theme', newTheme);
updateThemeIcon(newTheme);
// Add transition effect
body.style.transition = 'all 0.3s ease';
setTimeout(() => {
body.style.transition = '';
}, 300);
});
}
}
function updateThemeIcon(theme) {
const themeToggle = document.querySelector('.theme-toggle');
if (themeToggle) {
themeToggle.innerHTML = theme === 'dark' ? '<i class="fas fa-sun"></i>' : '<i class="fas fa-moon"></i>';
}
}
// Mobile Menu Functionality
function initMobileMenu() {
const mobileMenuBtn = document.querySelector('.mobile-menu-btn');
const navLinks = document.querySelector('.nav-links');
if (mobileMenuBtn && navLinks) {
mobileMenuBtn.addEventListener('click', () => {
mobileMenuBtn.classList.toggle('active');
navLinks.classList.toggle('active');
document.body.style.overflow = navLinks.classList.contains('active') ? 'hidden' : '';
});
// Close mobile menu when clicking on a link
navLinks.querySelectorAll('a').forEach(link => {
link.addEventListener('click', () => {
mobileMenuBtn.classList.remove('active');
navLinks.classList.remove('active');
document.body.style.overflow = '';
});
});
// Close mobile menu when clicking outside
document.addEventListener('click', (e) => {
if (!mobileMenuBtn.contains(e.target) && !navLinks.contains(e.target)) {
mobileMenuBtn.classList.remove('active');
navLinks.classList.remove('active');
document.body.style.overflow = '';
}
});
}
}
// Smooth Scrolling
function initSmoothScrolling() {
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
const offsetTop = target.offsetTop - 80; // Account for fixed navbar
window.scrollTo({
top: offsetTop,
behavior: 'smooth'
});
}
});
});
}
// Scroll Animations
function initScrollAnimations() {
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('visible');
// Add staggered animation for skill cards
if (entry.target.classList.contains('skill-card')) {
const cards = entry.target.parentElement.children;
Array.from(cards).forEach((card, index) => {
setTimeout(() => {
card.classList.add('visible');
}, index * 100);
});
}
}
});
}, observerOptions);
// Observe all elements with animation classes
document.querySelectorAll('.fade-in, .slide-in-left, .slide-in-right, .skill-card').forEach(el => {
observer.observe(el);
});
}
// Navbar Background on Scroll
function initNavbarScroll() {
const nav = document.querySelector('nav');
let lastScrollY = window.scrollY;
window.addEventListener('scroll', () => {
const currentScrollY = window.scrollY;
if (currentScrollY > 100) {
nav.style.background = 'rgba(255, 255, 255, 0.98)';
nav.style.boxShadow = '0 2px 20px rgba(0, 0, 0, 0.1)';
// Dark theme navbar
if (document.body.getAttribute('data-theme') === 'dark') {
nav.style.background = 'rgba(26, 32, 44, 0.98)';
}
} else {
nav.style.background = 'rgba(255, 255, 255, 0.95)';
nav.style.boxShadow = 'none';
// Dark theme navbar
if (document.body.getAttribute('data-theme') === 'dark') {
nav.style.background = 'rgba(26, 32, 44, 0.95)';
}
}
// Hide/show navbar on scroll
if (currentScrollY > lastScrollY && currentScrollY > 200) {
nav.style.transform = 'translateY(-100%)';
} else {
nav.style.transform = 'translateY(0)';
}
lastScrollY = currentScrollY;
});
}
// Typing Effect for Hero Section
function initTypingEffect() {
const heroTitle = document.querySelector('.hero h1');
if (heroTitle) {
const text = heroTitle.textContent;
heroTitle.textContent = '';
heroTitle.style.borderRight = '2px solid white';
let i = 0;
const typeWriter = () => {
if (i < text.length) {
heroTitle.textContent += text.charAt(i);
i++;
setTimeout(typeWriter, 100);
} else {
// Remove cursor after typing is complete
setTimeout(() => {
heroTitle.style.borderRight = 'none';
}, 1000);
}
};
// Start typing effect after a delay
setTimeout(typeWriter, 500);
}
}
// Particle Effect for Hero Section
function initParticleEffect() {
const hero = document.querySelector('.hero');
if (hero) {
// Create particles
for (let i = 0; i < 50; i++) {
createParticle(hero);
}
}
}
function createParticle(container) {
const particle = document.createElement('div');
particle.style.position = 'absolute';
particle.style.width = '2px';
particle.style.height = '2px';
particle.style.background = 'rgba(255, 255, 255, 0.5)';
particle.style.borderRadius = '50%';
particle.style.pointerEvents = 'none';
// Random position
particle.style.left = Math.random() * 100 + '%';
particle.style.top = Math.random() * 100 + '%';
// Random animation
const animation = particle.animate([
{
transform: 'translateY(0px)',
opacity: 0
},
{
opacity: 1
},
{
transform: 'translateY(-100px)',
opacity: 0
}
], {
duration: Math.random() * 3000 + 2000,
iterations: Infinity,
delay: Math.random() * 2000
});
container.appendChild(particle);
}
// Contact Form Functionality
function initContactForm() {
const contactForm = document.getElementById('contact-form');
if (contactForm) {
contactForm.addEventListener('submit', function(e) {
e.preventDefault();
// Get form data
const formData = new FormData(this);
const data = Object.fromEntries(formData);
// Simple validation
if (!data.name || !data.email || !data.message) {
showNotification('Please fill in all fields', 'error');
return;
}
if (!isValidEmail(data.email)) {
showNotification('Please enter a valid email address', 'error');
return;
}
// Simulate form submission
showNotification('Sending message...', 'info');
setTimeout(() => {
showNotification('Message sent successfully! I\'ll get back to you soon.', 'success');
contactForm.reset();
}, 2000);
});
}
}
function isValidEmail(email) {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}
function showNotification(message, type = 'info') {
// Remove existing notifications
const existingNotification = document.querySelector('.notification');
if (existingNotification) {
existingNotification.remove();
}
// Create notification element
const notification = document.createElement('div');
notification.className = `notification notification-${type}`;
notification.textContent = message;
// Add styles
notification.style.position = 'fixed';
notification.style.top = '20px';
notification.style.right = '20px';
notification.style.padding = '15px 20px';
notification.style.borderRadius = '5px';
notification.style.color = 'white';
notification.style.fontWeight = '500';
notification.style.zIndex = '10000';
notification.style.transform = 'translateX(100%)';
notification.style.transition = 'transform 0.3s ease';
// Set background color based on type
switch(type) {
case 'success':
notification.style.background = '#10b981';
break;
case 'error':
notification.style.background = '#ef4444';
break;
case 'info':
notification.style.background = '#3b82f6';
break;
default:
notification.style.background = '#6b7280';
}
document.body.appendChild(notification);
// Animate in
setTimeout(() => {
notification.style.transform = 'translateX(0)';
}, 100);
// Remove after 5 seconds
setTimeout(() => {
notification.style.transform = 'translateX(100%)';
setTimeout(() => {
notification.remove();
}, 300);
}, 5000);
}
// Utility Functions
function debounce(func, wait) {
let timeout;
return function executedFunction(...args) {
const later = () => {
clearTimeout(timeout);
func(...args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
}
// Performance optimization for scroll events
const debouncedScrollHandler = debounce(() => {
// Any scroll-based functionality can be added here
}, 10);
window.addEventListener('scroll', debouncedScrollHandler);
// Add some interactive features
document.addEventListener('DOMContentLoaded', function() {
// Add hover effects to skill cards
const skillCards = document.querySelectorAll('.skill-card');
skillCards.forEach(card => {
card.addEventListener('mouseenter', function() {
this.style.transform = 'translateY(-10px) scale(1.02)';
});
card.addEventListener('mouseleave', function() {
this.style.transform = 'translateY(0) scale(1)';
});
});
// Add click effects to buttons
const buttons = document.querySelectorAll('.btn');
buttons.forEach(button => {
button.addEventListener('click', function(e) {
// Create ripple effect
const ripple = document.createElement('span');
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';
ripple.classList.add('ripple');
this.appendChild(ripple);
setTimeout(() => {
ripple.remove();
}, 600);
});
});
});
// Add CSS for ripple effect
const style = document.createElement('style');
style.textContent = `
.btn {
position: relative;
overflow: hidden;
}
.ripple {
position: absolute;
border-radius: 50%;
background: rgba(255, 255, 255, 0.3);
transform: scale(0);
animation: ripple-animation 0.6s linear;
pointer-events: none;
}
@keyframes ripple-animation {
to {
transform: scale(4);
opacity: 0;
}
}
`;
document.head.appendChild(style);