-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
318 lines (272 loc) · 10.2 KB
/
script.js
File metadata and controls
318 lines (272 loc) · 10.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
// Mobile Menu Toggle
function toggleMenu() {
const hamburger = document.querySelector('.hamburger');
const mobileMenu = document.querySelector('.mobile-menu');
hamburger.classList.toggle('active');
mobileMenu.classList.toggle('active');
}
// Smooth scrolling for navigation links
document.addEventListener('DOMContentLoaded', function() {
// Get all navigation links
const navLinks = document.querySelectorAll('a[href^="#"]');
navLinks.forEach(link => {
link.addEventListener('click', function(e) {
e.preventDefault();
const targetId = this.getAttribute('href');
if (targetId === '#') return;
const targetSection = document.querySelector(targetId);
if (targetSection) {
const navHeight = document.querySelector('#navbar').offsetHeight;
const targetPosition = targetSection.offsetTop - navHeight;
window.scrollTo({
top: targetPosition,
behavior: 'smooth'
});
// Close mobile menu if open
const hamburger = document.querySelector('.hamburger');
const mobileMenu = document.querySelector('.mobile-menu');
hamburger.classList.remove('active');
mobileMenu.classList.remove('active');
}
});
});
});
// Navbar scroll effect
window.addEventListener('scroll', function() {
const navbar = document.querySelector('#navbar');
if (window.scrollY > 100) {
navbar.style.backgroundColor = 'rgba(2, 2, 49, 0.98)';
navbar.style.boxShadow = '0 2px 20px rgba(68, 61, 255, 0.1)';
} else {
navbar.style.backgroundColor = 'rgba(2, 2, 49, 0.95)';
navbar.style.boxShadow = 'none';
}
});
// Active navigation link highlighting
window.addEventListener('scroll', function() {
const sections = document.querySelectorAll('section[id]');
const navLinks = document.querySelectorAll('.nav-links a[href^="#"]');
let current = '';
sections.forEach(section => {
const sectionTop = section.offsetTop;
const sectionHeight = section.clientHeight;
if (scrollY >= sectionTop - 200) {
current = section.getAttribute('id');
}
});
navLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === `#${current}`) {
link.classList.add('active');
}
});
});
// Contact form handling
document.addEventListener('DOMContentLoaded', function() {
const contactForm = document.querySelector('#contactForm');
if (contactForm) {
contactForm.addEventListener('submit', function(e) {
e.preventDefault();
// Get form data
const formData = new FormData(this);
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)
submitForm({ name, email, subject, message });
});
}
});
// Email validation
function isValidEmail(email) {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}
// Form submission (replace with your actual form handling)
function submitForm(data) {
// Show loading state
const submitBtn = document.querySelector('#contactForm button[type="submit"]');
const originalText = submitBtn.textContent;
submitBtn.textContent = 'Sending...';
submitBtn.disabled = true;
// Simulate API call
setTimeout(() => {
// Reset button
submitBtn.textContent = originalText;
submitBtn.disabled = false;
// Show success message
showNotification('Message sent successfully! I\'ll get back to you soon.', 'success');
// Reset form
document.querySelector('#contactForm').reset();
// In a real application, you would send the data to your server:
// fetch('/api/contact', {
// method: 'POST',
// headers: { 'Content-Type': 'application/json' },
// body: JSON.stringify(data)
// })
// .then(response => response.json())
// .then(result => {
// if (result.success) {
// showNotification('Message sent successfully!', 'success');
// document.querySelector('#contactForm').reset();
// } else {
// showNotification('Failed to send message. Please try again.', 'error');
// }
// })
// .catch(error => {
// showNotification('An error occurred. Please try again.', 'error');
// });
}, 2000);
}
// 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 = `
<div class="notification-content">
<span class="notification-message">${message}</span>
<button class="notification-close" onclick="this.parentElement.parentElement.remove()">×</button>
</div>
`;
// Add styles
notification.style.cssText = `
position: fixed;
top: 20px;
right: 20px;
background-color: ${type === 'success' ? '#2f27ce' : type === 'error' ? '#ff00cb' : '#443dff'};
color: white;
padding: 1rem 1.5rem;
border-radius: 8px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
z-index: 10000;
max-width: 400px;
animation: slideInRight 0.3s ease-out;
`;
const content = notification.querySelector('.notification-content');
content.style.cssText = `
display: flex;
align-items: center;
justify-content: space-between;
gap: 1rem;
`;
const closeBtn = notification.querySelector('.notification-close');
closeBtn.style.cssText = `
background: none;
border: none;
color: white;
font-size: 1.5rem;
cursor: pointer;
padding: 0;
width: 24px;
height: 24px;
display: flex;
align-items: center;
justify-content: center;
`;
// Add to page
document.body.appendChild(notification);
// Auto remove after 5 seconds
setTimeout(() => {
if (notification.parentElement) {
notification.style.animation = 'slideOutRight 0.3s ease-out';
setTimeout(() => notification.remove(), 300);
}
}, 5000);
}
// Add CSS animations for notifications
if (!document.querySelector('#notification-styles')) {
const style = document.createElement('style');
style.id = 'notification-styles';
style.textContent = `
@keyframes slideInRight {
from {
transform: translateX(100%);
opacity: 0;
}
to {
transform: translateX(0);
opacity: 1;
}
}
@keyframes slideOutRight {
from {
transform: translateX(0);
opacity: 1;
}
to {
transform: translateX(100%);
opacity: 0;
}
}
`;
document.head.appendChild(style);
}
// Intersection Observer for scroll animations
document.addEventListener('DOMContentLoaded', function() {
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 all sections and cards
const elementsToAnimate = document.querySelectorAll('.skill-category, .project-card, .timeline-item, .contact-item');
elementsToAnimate.forEach(element => {
element.style.opacity = '0';
element.style.transform = 'translateY(30px)';
element.style.transition = 'opacity 0.6s ease-out, transform 0.6s ease-out';
observer.observe(element);
});
});
// Prevent form submission on Enter key in input fields (except textarea)
document.addEventListener('DOMContentLoaded', function() {
const formInputs = document.querySelectorAll('#contactForm input');
formInputs.forEach(input => {
input.addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
e.preventDefault();
const form = this.closest('form');
const submitBtn = form.querySelector('button[type="submit"]');
if (submitBtn) {
submitBtn.click();
}
}
});
});
});
// Add loading state to external links
document.addEventListener('DOMContentLoaded', function() {
const externalLinks = document.querySelectorAll('a[href^="http"], a[target="_blank"]');
externalLinks.forEach(link => {
link.addEventListener('click', function() {
// Add a small loading indicator or animation if desired
this.style.opacity = '0.7';
setTimeout(() => {
this.style.opacity = '1';
}, 300);
});
});
});
console.log('Portfolio loaded successfully! 🚀');