-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
348 lines (303 loc) · 11.2 KB
/
script.js
File metadata and controls
348 lines (303 loc) · 11.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
// Modern Portfolio JavaScript
document.addEventListener('DOMContentLoaded', function() {
// Theme toggle functionality
const themeToggle = document.querySelector('.theme-toggle');
const body = document.body;
const themeIcon = themeToggle.querySelector('i');
// Check for saved theme preference or default to dark
const savedTheme = localStorage.getItem('theme') || 'dark';
if (savedTheme === 'light') {
body.classList.add('light-theme');
themeIcon.classList.remove('fa-moon');
themeIcon.classList.add('fa-sun');
}
themeToggle.addEventListener('click', function() {
body.classList.toggle('light-theme');
if (body.classList.contains('light-theme')) {
themeIcon.classList.remove('fa-moon');
themeIcon.classList.add('fa-sun');
localStorage.setItem('theme', 'light');
} else {
themeIcon.classList.remove('fa-sun');
themeIcon.classList.add('fa-moon');
localStorage.setItem('theme', 'dark');
}
});
// Mobile menu toggle
const hamburger = document.querySelector('.hamburger');
const nav = document.querySelector('nav');
const header = document.querySelector('header');
if (hamburger && nav) {
hamburger.addEventListener('click', function() {
nav.classList.toggle('active');
hamburger.classList.toggle('active');
});
}
// Header scroll effect
window.addEventListener('scroll', function() {
if (window.scrollY > 100) {
header.classList.add('scrolled');
} else {
header.classList.remove('scrolled');
}
});
// Smooth scrolling for navigation 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',
block: 'start'
});
// Close mobile menu if open
nav.classList.remove('active');
hamburger.classList.remove('active');
}
});
});
// Active navigation highlighting
const sections = document.querySelectorAll('section[id]');
const navLinks = document.querySelectorAll('nav a[href^="#"]');
function updateActiveNavigation() {
const scrollPos = window.scrollY + 200;
sections.forEach(section => {
const top = section.offsetTop;
const bottom = top + section.offsetHeight;
const id = section.getAttribute('id');
if (scrollPos >= top && scrollPos <= bottom) {
navLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === `#${id}`) {
link.classList.add('active');
}
});
}
});
}
window.addEventListener('scroll', updateActiveNavigation);
// Portfolio filtering
const filterButtons = document.querySelectorAll('.filter-btn');
const portfolioItems = document.querySelectorAll('.portfolio-item');
filterButtons.forEach(button => {
button.addEventListener('click', function() {
const filter = this.getAttribute('data-filter');
// Update active button
filterButtons.forEach(btn => btn.classList.remove('active'));
this.classList.add('active');
// Filter portfolio items
portfolioItems.forEach(item => {
const category = item.getAttribute('data-category');
if (filter === 'all' || category === filter) {
item.style.display = 'block';
setTimeout(() => {
item.style.opacity = '1';
item.style.transform = 'translateY(0)';
}, 100);
} else {
item.style.opacity = '0';
item.style.transform = 'translateY(20px)';
setTimeout(() => {
item.style.display = 'none';
}, 300);
}
});
});
});
// Animate elements on scroll
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('animate-in');
}
});
}, observerOptions);
// Observe elements for animation
document.querySelectorAll('.portfolio-item, .timeline-item, .stat-item, .contact-item, .skill-item').forEach(el => {
observer.observe(el);
});
// Contact form handling with Formspree integration
const contactForm = document.querySelector('.contact-form');
if (contactForm) {
contactForm.addEventListener('submit', function(e) {
const submitBtn = this.querySelector('.btn-nth');
// Show loading state
submitBtn.textContent = 'Sending...';
submitBtn.disabled = true;
// Formspree will handle the actual submission
// We'll show success message after a short delay to indicate processing
setTimeout(() => {
if (!document.querySelector('.form-error')) {
showNotification('Message sent successfully! I\'ll get back to you soon.', 'success');
}
}, 1000);
});
}
// Typing animation enhancement
const typingText = document.querySelector('.typing-text span');
if (typingText) {
const words = ['Full Stack Developer', 'UI/UX Designer', 'Frontend Engineer', 'Web Developer', 'Software Engineer'];
let currentIndex = 0;
function typeWord(word, callback) {
let i = 0;
typingText.textContent = '';
function type() {
if (i < word.length) {
typingText.textContent += word.charAt(i);
i++;
setTimeout(type, 100);
} else {
setTimeout(callback, 2000);
}
}
type();
}
function startTyping() {
typeWord(words[currentIndex], () => {
currentIndex = (currentIndex + 1) % words.length;
startTyping();
});
}
// Start typing after a short delay
setTimeout(startTyping, 1000);
}
// Notification system
function showNotification(message, type = 'info') {
const notification = document.createElement('div');
notification.className = `notification ${type}`;
notification.textContent = message;
document.body.appendChild(notification);
setTimeout(() => {
notification.classList.add('show');
}, 100);
setTimeout(() => {
notification.classList.remove('show');
setTimeout(() => {
document.body.removeChild(notification);
}, 300);
}, 3000);
}
// Initialize animations
setTimeout(() => {
document.querySelectorAll('.home-content, .home-img').forEach(el => {
el.style.opacity = '1';
el.style.transform = 'translateY(0)';
});
}, 500);
// Initialize particle background
if (typeof particlesJS !== 'undefined') {
particlesJS('particles-js', {
particles: {
number: { value: 80, density: { enable: true, value_area: 800 } },
color: { value: '#6366f1' },
shape: { type: 'circle' },
opacity: { value: 0.5, random: false },
size: { value: 3, random: true },
line_linked: { enable: true, distance: 150, color: '#6366f1', opacity: 0.4, width: 1 },
move: {
enable: true,
speed: 2,
direction: 'none',
random: false,
straight: false,
out_mode: 'out',
bounce: false
}
},
interactivity: {
detect_on: 'canvas',
events: {
onhover: { enable: true, mode: 'repulse' },
onclick: { enable: true, mode: 'push' },
resize: true
},
modes: {
repulse: { distance: 100, duration: 0.4 },
push: { particles_nb: 4 }
}
},
retina_detect: true
});
}
// Resume download tracking
document.querySelectorAll('a[download]').forEach(link => {
link.addEventListener('click', function() {
showNotification('Resume download started!', 'success');
});
});
// Loading animation
window.addEventListener('load', function() {
document.body.classList.add('loaded');
// Stagger animation for sections
const sections = document.querySelectorAll('section');
sections.forEach((section, index) => {
setTimeout(() => {
section.classList.add('loaded');
}, index * 200);
});
});
// Performance optimization - lazy loading for images
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);
}
});
});
document.querySelectorAll('img[data-src]').forEach(img => {
imageObserver.observe(img);
});
}
});
// Add CSS for notifications and animations
const additionalCSS = `
.notification {
position: fixed;
top: 2rem;
right: 2rem;
padding: 1.5rem 2rem;
border-radius: var(--border-radius-md);
color: var(--text-primary);
font-weight: 500;
z-index: 10000;
transform: translateX(100%);
transition: transform 0.3s ease;
max-width: 30rem;
}
.notification.success {
background: var(--success-color);
}
.notification.show {
transform: translateX(0);
}
.animate-in {
opacity: 1 !important;
transform: translateY(0) !important;
}
.portfolio-item,
.timeline-item,
.stat-item,
.contact-item {
opacity: 0;
transform: translateY(20px);
transition: all 0.6s ease;
}
.home-content,
.home-img {
opacity: 0;
transform: translateY(30px);
transition: all 1s ease;
}
`;
const style = document.createElement('style');
style.textContent = additionalCSS;
document.head.appendChild(style);