-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
318 lines (274 loc) · 9.94 KB
/
script.js
File metadata and controls
318 lines (274 loc) · 9.94 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
// Theme Toggle Functionality
const themeToggle = document.getElementById('themeToggle');
const htmlElement = document.documentElement;
// Check for saved theme preference or default to dark mode
const currentTheme = localStorage.getItem('theme') || 'dark';
htmlElement.setAttribute('data-theme', currentTheme);
updateThemeIcon(currentTheme);
// Theme toggle event listener
themeToggle.addEventListener('click', () => {
const currentTheme = htmlElement.getAttribute('data-theme');
const newTheme = currentTheme === 'light' ? 'dark' : 'light';
htmlElement.setAttribute('data-theme', newTheme);
localStorage.setItem('theme', newTheme);
updateThemeIcon(newTheme);
// Add a subtle animation
themeToggle.style.transform = 'rotate(360deg)';
setTimeout(() => {
themeToggle.style.transform = 'rotate(0deg)';
}, 300);
});
// Update theme icon
function updateThemeIcon(theme) {
const icon = themeToggle.querySelector('i');
if (theme === 'dark') {
icon.classList.remove('fa-moon');
icon.classList.add('fa-sun');
} else {
icon.classList.remove('fa-sun');
icon.classList.add('fa-moon');
}
}
// Smooth scroll for anchor 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'
});
}
});
});
// Navbar background on scroll
const navbar = document.querySelector('.navbar');
let lastScroll = 0;
window.addEventListener('scroll', () => {
const currentScroll = window.pageYOffset;
if (currentScroll > 100) {
navbar.style.boxShadow = 'var(--shadow-md)';
} else {
navbar.style.boxShadow = 'var(--shadow-sm)';
}
lastScroll = currentScroll;
});
// Add animation on scroll for elements
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -100px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}
});
}, observerOptions);
// Observe elements for animation
document.querySelectorAll('.publication-card, .project-card, .interest-card, .passion-card, .mosaic-card').forEach(el => {
el.style.opacity = '0';
el.style.transform = 'translateY(30px)';
el.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
observer.observe(el);
});
// Publications page - Filter functionality
if (document.querySelector('.filter-btn')) {
const filterButtons = document.querySelectorAll('.filter-btn');
filterButtons.forEach(button => {
button.addEventListener('click', () => {
// Remove active class from all buttons
filterButtons.forEach(btn => btn.classList.remove('active'));
// Add active class to clicked button
button.classList.add('active');
// Here you can add filtering logic based on button text
const filterType = button.textContent.trim();
console.log('Filter by:', filterType);
// Example: Show/hide publications based on type
// This is a placeholder - implement based on your needs
});
});
}
// Add hover effect to social links
document.querySelectorAll('.social-links a').forEach(link => {
link.addEventListener('mouseenter', function() {
this.style.transform = 'translateY(-5px) scale(1.1)';
});
link.addEventListener('mouseleave', function() {
this.style.transform = 'translateY(0) scale(1)';
});
});
// Stats counter animation (for homepage)
function animateStats() {
const stats = document.querySelectorAll('.stat-number');
stats.forEach(stat => {
const target = stat.textContent.replace(/[^\d]/g, ''); // Extract numbers
if (!target) return;
const targetNum = parseInt(target);
const duration = 2000; // 2 seconds
const increment = targetNum / (duration / 16); // 60 FPS
let current = 0;
const updateCounter = () => {
current += increment;
if (current < targetNum) {
stat.textContent = Math.floor(current);
requestAnimationFrame(updateCounter);
} else {
stat.textContent = stat.textContent; // Keep original format with brackets
}
};
// Start animation when element is visible
const statObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
updateCounter();
statObserver.unobserve(entry.target);
}
});
});
statObserver.observe(stat);
});
}
// Initialize stats animation if on homepage
if (document.querySelector('.stat-number')) {
animateStats();
}
// Mobile menu toggle
const hamburger = document.getElementById('hamburger');
const navMenu = document.getElementById('navMenu');
if (hamburger && navMenu) {
hamburger.addEventListener('click', () => {
navMenu.classList.toggle('active');
const icon = hamburger.querySelector('i');
if (navMenu.classList.contains('active')) {
icon.classList.remove('fa-bars');
icon.classList.add('fa-times');
} else {
icon.classList.remove('fa-times');
icon.classList.add('fa-bars');
}
});
// Close menu when clicking on a link
const navLinks = navMenu.querySelectorAll('.nav-link');
navLinks.forEach(link => {
link.addEventListener('click', () => {
if (window.innerWidth <= 768) {
navMenu.classList.remove('active');
const icon = hamburger.querySelector('i');
icon.classList.remove('fa-times');
icon.classList.add('fa-bars');
}
});
});
// Close menu when clicking outside
document.addEventListener('click', (e) => {
if (!navMenu.contains(e.target) && !hamburger.contains(e.target) && navMenu.classList.contains('active')) {
navMenu.classList.remove('active');
const icon = hamburger.querySelector('i');
icon.classList.remove('fa-times');
icon.classList.add('fa-bars');
}
});
}
// Add loading animation
window.addEventListener('load', () => {
document.body.style.opacity = '0';
setTimeout(() => {
document.body.style.transition = 'opacity 0.5s ease';
document.body.style.opacity = '1';
}, 100);
});
// Typing effect for hero title (optional enhancement)
function typeWriter(element, text, speed = 100) {
let i = 0;
element.textContent = '';
function type() {
if (i < text.length) {
element.textContent += text.charAt(i);
i++;
setTimeout(type, speed);
}
}
type();
}
// Add parallax effect to hero section
if (document.querySelector('.hero')) {
window.addEventListener('scroll', () => {
const scrolled = window.pageYOffset;
const hero = document.querySelector('.hero');
// Disabled parallax to prevent overlay issues
// if (hero) {
// hero.style.transform = `translateY(${scrolled * 0.5}px)`;
// }
});
}
// Console message for developers
console.log('%c👋 Hello, curious developer!', 'color: #3b82f6; font-size: 20px; font-weight: bold;');
console.log('%cThanks for checking out my portfolio. Feel free to reach out if you want to collaborate!', 'color: #6b7280; font-size: 14px;');
// Add copy email functionality
document.querySelectorAll('a[href^="mailto:"]').forEach(link => {
link.addEventListener('click', (e) => {
const email = link.getAttribute('href').replace('mailto:', '');
// Try to copy to clipboard
if (navigator.clipboard) {
navigator.clipboard.writeText(email).then(() => {
// Show a subtle notification
const notification = document.createElement('div');
notification.textContent = 'Email copied to clipboard!';
notification.style.cssText = `
position: fixed;
bottom: 20px;
right: 20px;
background-color: var(--accent-color);
color: white;
padding: 1rem 2rem;
border-radius: 8px;
box-shadow: var(--shadow-lg);
z-index: 10000;
animation: slideIn 0.3s ease;
`;
document.body.appendChild(notification);
setTimeout(() => {
notification.style.animation = 'slideOut 0.3s ease';
setTimeout(() => notification.remove(), 300);
}, 2000);
});
}
});
});
// Add CSS for notifications
const style = document.createElement('style');
style.textContent = `
@keyframes slideIn {
from {
transform: translateX(400px);
opacity: 0;
}
to {
transform: translateX(0);
opacity: 1;
}
}
@keyframes slideOut {
from {
transform: translateX(0);
opacity: 1;
}
to {
transform: translateX(400px);
opacity: 0;
}
}
@media (max-width: 480px) {
div[style*="position: fixed"] {
bottom: 10px !important;
right: 10px !important;
left: 10px !important;
padding: 0.75rem 1rem !important;
font-size: 0.9rem !important;
}
}
`;
document.head.appendChild(style);