-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
351 lines (294 loc) · 11.2 KB
/
script.js
File metadata and controls
351 lines (294 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
349
350
351
document.addEventListener('DOMContentLoaded', () => {
initNavigation();
initScrollHighlight();
initAnimations();
initFormHandling();
initThemeToggle();
initTypewriter();
});
function initNavigation() {
const mobileMenuToggle = document.querySelector('.mobile-menu-toggle');
const navList = document.querySelector('.nav-list');
const navLinks = document.querySelectorAll('.nav-link');
if (mobileMenuToggle) {
mobileMenuToggle.addEventListener('click', () => {
navList.classList.toggle('active');
const isExpanded = navList.classList.contains('active');
mobileMenuToggle.setAttribute('aria-expanded', isExpanded);
});
}
navLinks.forEach(link => {
link.addEventListener('click', (e) => {
e.preventDefault();
const targetSection = link.getAttribute('data-section');
const targetElement = document.getElementById(targetSection);
navLinks.forEach(l => l.classList.remove('active'));
link.classList.add('active');
if (targetElement) {
const headerOffset = 80;
const elementPosition = targetElement.getBoundingClientRect().top;
const offsetPosition = elementPosition + window.pageYOffset - headerOffset;
window.scrollTo({
top: offsetPosition,
behavior: 'smooth'
});
history.pushState(null, '', `#${targetSection}`);
}
if (navList.classList.contains('active')) {
navList.classList.remove('active');
}
});
});
}
function initScrollHighlight() {
const sections = document.querySelectorAll('.section');
const navLinks = document.querySelectorAll('.nav-link');
// Handle initial hash
const hash = window.location.hash.slice(1);
if (hash) {
const targetElement = document.getElementById(hash);
if (targetElement) {
setTimeout(() => {
const headerOffset = 80;
const elementPosition = targetElement.getBoundingClientRect().top;
const offsetPosition = elementPosition + window.pageYOffset - headerOffset;
window.scrollTo({
top: offsetPosition,
behavior: 'smooth'
});
}, 100);
}
}
// Highlight nav link based on scroll position
const highlightNavOnScroll = () => {
let current = '';
const scrollPosition = window.pageYOffset + 100;
sections.forEach(section => {
const sectionTop = section.offsetTop;
const sectionHeight = section.clientHeight;
if (scrollPosition >= sectionTop && scrollPosition < sectionTop + sectionHeight) {
current = section.getAttribute('id');
}
});
navLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('data-section') === current) {
link.classList.add('active');
}
});
};
window.addEventListener('scroll', highlightNavOnScroll);
highlightNavOnScroll();
}
function initAnimations() {
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}
});
}, observerOptions);
const animatedElements = document.querySelectorAll('.project-card, .timeline-item, .stat-card, .cert-card');
animatedElements.forEach(el => {
el.style.opacity = '0';
el.style.transform = 'translateY(20px)';
el.style.transition = 'opacity 0.5s ease, transform 0.5s ease';
observer.observe(el);
});
}
function initFormHandling() {
const contactForm = document.querySelector('.contact-form');
if (contactForm) {
contactForm.addEventListener('submit', async (e) => {
e.preventDefault();
const formData = new FormData(contactForm);
const data = Object.fromEntries(formData);
const submitButton = contactForm.querySelector('button[type="submit"]');
const originalText = submitButton.textContent;
submitButton.textContent = 'Sending...';
submitButton.disabled = true;
setTimeout(() => {
alert('Thank you for your message! I will get back to you soon.');
contactForm.reset();
submitButton.textContent = originalText;
submitButton.disabled = false;
}, 1500);
});
}
}
function initThemeToggle() {
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)');
const currentTheme = localStorage.getItem('theme');
if (currentTheme === 'dark' || (!currentTheme && prefersDark.matches)) {
document.documentElement.setAttribute('data-theme', 'dark');
}
const createThemeToggle = () => {
const toggle = document.createElement('button');
toggle.className = 'theme-toggle';
toggle.setAttribute('aria-label', 'Toggle theme');
toggle.innerHTML = `
<svg class="sun-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="12" cy="12" r="5"></circle>
<line x1="12" y1="1" x2="12" y2="3"></line>
<line x1="12" y1="21" x2="12" y2="23"></line>
<line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line>
<line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line>
<line x1="1" y1="12" x2="3" y2="12"></line>
<line x1="21" y1="12" x2="23" y2="12"></line>
<line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line>
<line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line>
</svg>
<svg class="moon-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"></path>
</svg>
`;
toggle.addEventListener('click', () => {
const currentTheme = document.documentElement.getAttribute('data-theme');
const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
document.documentElement.setAttribute('data-theme', newTheme);
localStorage.setItem('theme', newTheme);
});
document.body.appendChild(toggle);
};
const style = document.createElement('style');
style.textContent = `
.theme-toggle {
position: fixed;
bottom: 2rem;
right: 2rem;
width: 50px;
height: 50px;
border-radius: 50%;
background: var(--primary-color);
border: none;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
box-shadow: var(--shadow-lg);
transition: var(--transition);
z-index: 999;
}
.theme-toggle:hover {
transform: scale(1.1);
box-shadow: var(--shadow-xl);
}
.theme-toggle svg {
width: 24px;
height: 24px;
color: white;
position: absolute;
transition: var(--transition);
}
.sun-icon {
opacity: 1;
transform: scale(1) rotate(0deg);
}
.moon-icon {
opacity: 0;
transform: scale(0) rotate(180deg);
}
[data-theme="dark"] .sun-icon {
opacity: 0;
transform: scale(0) rotate(180deg);
}
[data-theme="dark"] .moon-icon {
opacity: 1;
transform: scale(1) rotate(0deg);
}
`;
document.head.appendChild(style);
createThemeToggle();
}
function initTypewriter() {
const codeContent = document.querySelector('.code-content code');
if (!codeContent) return;
const originalHTML = codeContent.innerHTML;
const text = codeContent.textContent;
let index = 0;
codeContent.innerHTML = '';
function typeChar() {
if (index < text.length) {
const char = text[index];
const span = document.createElement('span');
span.textContent = char;
span.style.opacity = '0';
codeContent.appendChild(span);
setTimeout(() => {
span.style.opacity = '1';
}, 50);
index++;
setTimeout(typeChar, 50);
} else {
setTimeout(() => {
codeContent.innerHTML = originalHTML;
}, 500);
}
}
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
typeChar();
observer.disconnect();
}
});
});
observer.observe(codeContent);
}
window.addEventListener('popstate', () => {
const hash = window.location.hash.slice(1) || 'home';
const targetElement = document.getElementById(hash);
if (targetElement) {
const headerOffset = 80;
const elementPosition = targetElement.getBoundingClientRect().top;
const offsetPosition = elementPosition + window.pageYOffset - headerOffset;
window.scrollTo({
top: offsetPosition,
behavior: 'smooth'
});
}
});
document.addEventListener('scroll', () => {
const header = document.querySelector('.header');
const scrolled = window.scrollY > 100;
if (scrolled) {
header.style.boxShadow = 'var(--shadow-md)';
} else {
header.style.boxShadow = 'none';
}
});
const projectCards = document.querySelectorAll('.project-card');
projectCards.forEach(card => {
card.addEventListener('mouseenter', (e) => {
const rect = card.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
card.style.setProperty('--mouse-x', `${x}px`);
card.style.setProperty('--mouse-y', `${y}px`);
});
});
const style = document.createElement('style');
style.textContent = `
.project-card::before {
content: '';
position: absolute;
top: var(--mouse-y, 50%);
left: var(--mouse-x, 50%);
transform: translate(-50%, -50%);
width: 300px;
height: 300px;
background: radial-gradient(circle, rgba(37, 99, 235, 0.1) 0%, transparent 70%);
opacity: 0;
transition: opacity 0.3s;
pointer-events: none;
}
.project-card:hover::before {
opacity: 1;
}
`;
document.head.appendChild(style);