-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
264 lines (233 loc) · 9.04 KB
/
script.js
File metadata and controls
264 lines (233 loc) · 9.04 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
// Mobile navigation toggle
document.addEventListener('DOMContentLoaded', function() {
const mobileMenu = document.getElementById('mobile-menu');
const navMenu = document.querySelector('.nav-menu');
// Toggle mobile menu
mobileMenu.addEventListener('click', function() {
navMenu.classList.toggle('active');
// Animate hamburger menu
mobileMenu.classList.toggle('active');
// Toggle bars animation
const bars = mobileMenu.querySelectorAll('.bar');
bars.forEach((bar, index) => {
if (mobileMenu.classList.contains('active')) {
if (index === 0) {
bar.style.transform = 'rotate(-45deg) translate(-5px, 6px)';
} else if (index === 1) {
bar.style.opacity = '0';
} else if (index === 2) {
bar.style.transform = 'rotate(45deg) translate(-5px, -6px)';
}
} else {
bar.style.transform = 'none';
bar.style.opacity = '1';
}
});
});
// Close mobile menu when clicking on a link
const navLinks = document.querySelectorAll('.nav-link');
navLinks.forEach(link => {
link.addEventListener('click', () => {
navMenu.classList.remove('active');
mobileMenu.classList.remove('active');
// Reset hamburger menu
const bars = mobileMenu.querySelectorAll('.bar');
bars.forEach(bar => {
bar.style.transform = 'none';
bar.style.opacity = '1';
});
});
});
// Close mobile menu when clicking outside
document.addEventListener('click', function(e) {
if (!mobileMenu.contains(e.target) && !navMenu.contains(e.target)) {
navMenu.classList.remove('active');
mobileMenu.classList.remove('active');
// Reset hamburger menu
const bars = mobileMenu.querySelectorAll('.bar');
bars.forEach(bar => {
bar.style.transform = 'none';
bar.style.opacity = '1';
});
}
});
});
// Smooth scrolling 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'
});
}
});
});
// Add scroll effect to navbar
window.addEventListener('scroll', function() {
const navbar = document.querySelector('.navbar');
if (window.scrollY > 50) {
navbar.style.backgroundColor = 'rgba(255, 255, 255, 0.95)';
navbar.style.backdropFilter = 'blur(10px)';
} else {
navbar.style.backgroundColor = 'var(--bg-white)';
navbar.style.backdropFilter = 'none';
}
});
// Lazy loading for images
document.addEventListener('DOMContentLoaded', function() {
const images = document.querySelectorAll('img[data-src]');
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);
}
});
});
images.forEach(img => imageObserver.observe(img));
});
// Add animation on scroll for cards and sections
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver(function(entries) {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}
});
}, observerOptions);
// Observe elements for animation
document.addEventListener('DOMContentLoaded', function() {
const animatedElements = document.querySelectorAll(
'.overview-card, .project-card, .experience-item, .certification-card, .achievement-card, .interest-card'
);
animatedElements.forEach(el => {
el.style.opacity = '0';
el.style.transform = 'translateY(20px)';
el.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
observer.observe(el);
});
});
// Contact form validation (if you add a contact form later)
function validateEmail(email) {
const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return re.test(email);
}
// Copy email to clipboard functionality
function copyToClipboard(text) {
navigator.clipboard.writeText(text).then(function() {
// You can add a toast notification here
console.log('Email copied to clipboard');
}, function(err) {
console.error('Could not copy text: ', err);
});
}
// Add click handlers for email links
document.addEventListener('DOMContentLoaded', function() {
const emailLinks = document.querySelectorAll('a[href^="mailto:"]');
emailLinks.forEach(link => {
link.addEventListener('contextmenu', function(e) {
e.preventDefault();
const email = this.href.replace('mailto:', '');
copyToClipboard(email);
});
});
});
// Theme toggle functionality (optional - for dark mode)
function toggleTheme() {
const body = document.body;
const currentTheme = body.getAttribute('data-theme');
const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
body.setAttribute('data-theme', newTheme);
localStorage.setItem('theme', newTheme);
}
// Load saved theme
document.addEventListener('DOMContentLoaded', function() {
const savedTheme = localStorage.getItem('theme') || 'light';
document.body.setAttribute('data-theme', savedTheme);
});
// Add loading states for external links
document.addEventListener('DOMContentLoaded', function() {
const externalLinks = document.querySelectorAll('a[href^="http"]');
externalLinks.forEach(link => {
link.addEventListener('click', function() {
this.style.opacity = '0.7';
this.innerHTML += ' <span>Loading...</span>';
});
});
});
// Simple analytics tracking (you can replace with Google Analytics)
function trackEvent(category, action, label) {
// Replace with your analytics tracking code
console.log(`Event tracked: ${category} - ${action} - ${label}`);
}
// Track portfolio interactions
document.addEventListener('DOMContentLoaded', function() {
// Track project clicks
const projectLinks = document.querySelectorAll('.project-btn');
projectLinks.forEach(link => {
link.addEventListener('click', function() {
trackEvent('Portfolio', 'Project Click', this.closest('.project-card').querySelector('h3').textContent);
});
});
// Track contact clicks
const contactLinks = document.querySelectorAll('.contact-btn');
contactLinks.forEach(link => {
link.addEventListener('click', function() {
trackEvent('Contact', 'Contact Click', this.textContent);
});
});
});
// Keyboard navigation enhancement
document.addEventListener('keydown', function(e) {
// ESC key closes mobile menu
if (e.key === 'Escape') {
const navMenu = document.querySelector('.nav-menu');
const mobileMenu = document.getElementById('mobile-menu');
if (navMenu.classList.contains('active')) {
navMenu.classList.remove('active');
mobileMenu.classList.remove('active');
}
}
});
// Print optimization
window.addEventListener('beforeprint', function() {
// Expand all collapsed sections for printing
const cards = document.querySelectorAll('.project-card, .experience-item');
cards.forEach(card => {
card.style.pageBreakInside = 'avoid';
});
});
// Performance optimization - lazy load heavy content
document.addEventListener('DOMContentLoaded', function() {
// Lazy load heavy sections
const sections = document.querySelectorAll('section');
const sectionObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('loaded');
}
});
}, { threshold: 0.1 });
sections.forEach(section => {
sectionObserver.observe(section);
});
});
// Error handling for broken images
document.addEventListener('DOMContentLoaded', function() {
const images = document.querySelectorAll('img');
images.forEach(img => {
img.addEventListener('error', function() {
this.src = 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzAwIiBoZWlnaHQ9IjIwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cmVjdCB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiBmaWxsPSIjZGRkIi8+PHRleHQgeD0iNTAlIiB5PSI1MCUiIGZvbnQtZmFtaWx5PSJBcmlhbCwgc2Fucy1zZXJpZiIgZm9udC1zaXplPSIxNCIgZmlsbD0iIzk5OSIgdGV4dC1hbmNob3I9Im1pZGRsZSIgZHk9Ii4zZW0iPkltYWdlIE5vdCBGb3VuZDwvdGV4dD48L3N2Zz4=';
this.alt = 'Image not found';
});
});
});