-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
438 lines (370 loc) Β· 13.8 KB
/
Copy pathscript.js
File metadata and controls
438 lines (370 loc) Β· 13.8 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
430
431
432
433
434
435
436
437
438
// Smooth scrolling navigation
document.addEventListener('DOMContentLoaded', function() {
// Mobile menu toggle
const mobileMenu = document.getElementById('mobile-menu');
const navMenu = document.getElementById('nav-menu');
mobileMenu.addEventListener('click', function() {
mobileMenu.classList.toggle('active');
navMenu.classList.toggle('active');
});
// Close mobile menu when clicking on nav links
const navLinks = document.querySelectorAll('.nav-link');
navLinks.forEach(link => {
link.addEventListener('click', function() {
mobileMenu.classList.remove('active');
navMenu.classList.remove('active');
});
});
// Navbar scroll effect
const navbar = document.getElementById('navbar');
let lastScrollTop = 0;
window.addEventListener('scroll', function() {
let scrollTop = window.pageYOffset || document.documentElement.scrollTop;
if (scrollTop > 50) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
lastScrollTop = scrollTop;
});
// Active navigation link highlighting
const sections = document.querySelectorAll('section[id]');
function highlightNavigation() {
let scrollY = window.pageYOffset;
sections.forEach(current => {
const sectionHeight = current.offsetHeight;
const sectionTop = current.offsetTop - 100;
const sectionId = current.getAttribute('id');
if (scrollY > sectionTop && scrollY <= sectionTop + sectionHeight) {
const activeLink = document.querySelector('.nav-menu a[href*=' + sectionId + ']');
// Remove active class from all links
navLinks.forEach(link => {
link.classList.remove('active');
});
// Add active class to current link
if (activeLink) {
activeLink.classList.add('active');
}
}
});
}
window.addEventListener('scroll', highlightNavigation);
// Project filtering
const filterButtons = document.querySelectorAll('.filter-btn');
const projectCards = document.querySelectorAll('.project-card');
filterButtons.forEach(button => {
button.addEventListener('click', function() {
const filterValue = this.getAttribute('data-filter');
// Update active filter button
filterButtons.forEach(btn => btn.classList.remove('active'));
this.classList.add('active');
// Filter projects
projectCards.forEach(card => {
const cardCategory = card.getAttribute('data-category');
if (filterValue === 'all' || cardCategory === filterValue) {
card.style.display = 'block';
card.style.animation = 'fadeIn 0.5s ease';
} else {
card.style.display = 'none';
}
});
});
});
// Intersection Observer for fade-in animations
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('visible');
}
});
}, observerOptions);
// Observe elements for animation
const animatedElements = document.querySelectorAll('.project-card, .skill-category, .contact-method');
animatedElements.forEach(el => {
el.classList.add('fade-in');
observer.observe(el);
});
// Captcha functionality
let captchaAnswer = 0;
function generateCaptcha() {
const num1 = Math.floor(Math.random() * 20) + 1;
const num2 = Math.floor(Math.random() * 20) + 1;
const operations = ['+', '-', 'Γ'];
const operation = operations[Math.floor(Math.random() * operations.length)];
let question, answer;
switch (operation) {
case '+':
question = `${num1} + ${num2} = ?`;
answer = num1 + num2;
break;
case '-':
const larger = Math.max(num1, num2);
const smaller = Math.min(num1, num2);
question = `${larger} - ${smaller} = ?`;
answer = larger - smaller;
break;
case 'Γ':
const smallNum1 = Math.floor(Math.random() * 10) + 1;
const smallNum2 = Math.floor(Math.random() * 10) + 1;
question = `${smallNum1} Γ ${smallNum2} = ?`;
answer = smallNum1 * smallNum2;
break;
}
captchaAnswer = answer;
const captchaQuestion = document.getElementById('captchaQuestion');
if (captchaQuestion) {
captchaQuestion.textContent = question;
}
}
// Initialize captcha
generateCaptcha();
// Refresh captcha button
const refreshBtn = document.getElementById('refreshCaptcha');
if (refreshBtn) {
refreshBtn.addEventListener('click', function() {
generateCaptcha();
const captchaInput = document.getElementById('captcha');
if (captchaInput) {
captchaInput.value = '';
}
});
}
// Contact form handling with captcha validation
const contactForm = document.getElementById('contact-form');
contactForm.addEventListener('submit', function(e) {
e.preventDefault();
// Validate captcha first
const captchaInput = document.getElementById('captcha');
const userAnswer = parseInt(captchaInput.value);
if (userAnswer !== captchaAnswer) {
showNotification('Incorrect security answer. Please try again.', 'error');
generateCaptcha();
captchaInput.value = '';
captchaInput.focus();
return;
}
// Get form data
const formData = new FormData(contactForm);
const name = formData.get('name');
const email = formData.get('email');
const subject = formData.get('subject');
const message = formData.get('message');
// Basic form validation
if (!name || !email || !subject || !message) {
showNotification('Please fill in all fields.', 'error');
return;
}
if (!isValidEmail(email)) {
showNotification('Please enter a valid email address.', 'error');
return;
}
// Simulate form submission (replace with actual form handling)
showNotification('Thank you for your message! We\'ll get back to you soon.', 'success');
contactForm.reset();
generateCaptcha(); // Generate new captcha after successful submission
// In a real implementation, you would send the data to a server
// Example: sendEmailToServer(name, email, subject, message);
});
// Email validation function
function isValidEmail(email) {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}
// Notification system
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.innerHTML = `
<span>${message}</span>
<button class="notification-close">×</button>
`;
// Add styles
notification.style.cssText = `
position: fixed;
top: 20px;
right: 20px;
background: ${type === 'success' ? '#10b981' : type === 'error' ? '#ef4444' : '#3b82f6'};
color: white;
padding: 1rem 1.5rem;
border-radius: 0.5rem;
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
z-index: 1001;
display: flex;
align-items: center;
gap: 1rem;
max-width: 400px;
animation: slideInRight 0.3s ease;
`;
// Add close button functionality
const closeButton = notification.querySelector('.notification-close');
closeButton.style.cssText = `
background: none;
border: none;
color: white;
font-size: 1.25rem;
cursor: pointer;
padding: 0;
margin-left: auto;
`;
closeButton.addEventListener('click', () => {
notification.remove();
});
// Add to document
document.body.appendChild(notification);
// Auto remove after 5 seconds
setTimeout(() => {
if (notification.parentNode) {
notification.remove();
}
}, 5000);
}
// Smooth reveal animation for project cards
function revealProjectCards() {
const visibleCards = Array.from(projectCards).filter(card =>
card.style.display !== 'none'
);
visibleCards.forEach((card, index) => {
setTimeout(() => {
card.style.opacity = '0';
card.style.transform = 'translateY(20px)';
card.style.transition = 'all 0.4s ease';
setTimeout(() => {
card.style.opacity = '1';
card.style.transform = 'translateY(0)';
}, 50);
}, index * 100);
});
}
// Initialize project cards animation
revealProjectCards();
// Typing effect for hero title (optional enhancement)
function typeWriter(element, text, speed = 100) {
let i = 0;
element.innerHTML = '';
function type() {
if (i < text.length) {
element.innerHTML += text.charAt(i);
i++;
setTimeout(type, speed);
}
}
type();
}
// Add CSS animations
const style = document.createElement('style');
style.textContent = `
@keyframes slideInRight {
from {
transform: translateX(100%);
opacity: 0;
}
to {
transform: translateX(0);
opacity: 1;
}
}
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.nav-link.active {
color: var(--primary-color);
}
.nav-link.active::after {
width: 100%;
}
`;
document.head.appendChild(style);
// Performance optimization: Throttle scroll events
function throttle(func, limit) {
let inThrottle;
return function() {
const args = arguments;
const context = this;
if (!inThrottle) {
func.apply(context, args);
inThrottle = true;
setTimeout(() => inThrottle = false, limit);
}
}
}
// Apply throttling to scroll events
window.addEventListener('scroll', throttle(highlightNavigation, 100));
// Lazy loading for images (if needed)
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 keyboard navigation support
document.addEventListener('keydown', function(e) {
// ESC key closes mobile menu
if (e.key === 'Escape') {
mobileMenu.classList.remove('active');
navMenu.classList.remove('active');
}
});
// Console welcome message
console.log(`
π Portfolio Website Loaded Successfully!
Features:
β
Responsive Design
β
Smooth Scrolling Navigation
β
Project Filtering
β
Contact Form Validation
β
Intersection Observer Animations
β
Mobile-Friendly Navigation
Customize this template by:
1. Updating personal information in index.html
2. Adding your own project images and links
3. Modifying colors in CSS custom properties
4. Adding your own content and sections
Happy coding! π¨
`);
});
// Utility function for smooth scrolling (backup for older browsers)
function smoothScrollTo(target) {
const element = document.querySelector(target);
if (element) {
const offset = 80; // Account for fixed navbar
const elementPosition = element.offsetTop - offset;
window.scrollTo({
top: elementPosition,
behavior: 'smooth'
});
}
}
// Export functions for potential external use
window.portfolioUtils = {
smoothScrollTo,
showNotification: function(message, type) {
// Reference to the showNotification function defined above
console.log(`Notification: ${message} (${type})`);
}
};