-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
435 lines (381 loc) · 13.1 KB
/
Copy pathscript.js
File metadata and controls
435 lines (381 loc) · 13.1 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
// Mobile Navigation Toggle
const hamburger = document.querySelector('.hamburger');
const navMenu = document.querySelector('.nav-menu');
hamburger.addEventListener('click', () => {
hamburger.classList.toggle('active');
navMenu.classList.toggle('active');
});
// Close mobile menu when clicking on a link
document.querySelectorAll('.nav-link').forEach(n => n.addEventListener('click', () => {
hamburger.classList.remove('active');
navMenu.classList.remove('active');
}));
// Typing Animation
const typedTextSpan = document.querySelector('.typed-text');
const cursorSpan = document.querySelector('.cursor');
const textArray = ['Web Developer', 'Frontend Developer', 'Backend Developer', 'Full-Stack Developer'];
const typingDelay = 100;
const erasingDelay = 50;
const newTextDelay = 1000;
let textArrayIndex = 0;
let charIndex = 0;
function type() {
if (charIndex < textArray[textArrayIndex].length) {
if (!cursorSpan.classList.contains('typing')) cursorSpan.classList.add('typing');
typedTextSpan.textContent += textArray[textArrayIndex].charAt(charIndex);
charIndex++;
setTimeout(type, typingDelay);
} else {
cursorSpan.classList.remove('typing');
setTimeout(erase, newTextDelay);
}
}
function erase() {
if (charIndex > 0) {
if (!cursorSpan.classList.contains('typing')) cursorSpan.classList.add('typing');
typedTextSpan.textContent = textArray[textArrayIndex].substring(0, charIndex - 1);
charIndex--;
setTimeout(erase, erasingDelay);
} else {
cursorSpan.classList.remove('typing');
textArrayIndex++;
if (textArrayIndex >= textArray.length) textArrayIndex = 0;
setTimeout(type, typingDelay + 1100);
}
}
document.addEventListener('DOMContentLoaded', function() {
if (textArray.length) setTimeout(type, newTextDelay + 250);
});
// Smooth scrolling for navigation 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 change on scroll
window.addEventListener('scroll', () => {
const navbar = document.querySelector('.navbar');
if (window.scrollY > 50) {
navbar.style.background = 'rgba(255, 255, 255, 0.98)';
navbar.style.boxShadow = '0 2px 10px rgba(0, 0, 0, 0.1)';
} else {
navbar.style.background = 'rgba(255, 255, 255, 0.95)';
navbar.style.boxShadow = 'none';
}
});
// Intersection Observer for animations
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
// Animate skill bars when skills section is visible
if (entry.target.classList.contains('skills')) {
animateSkillBars();
}
}
});
}, observerOptions);
// Add fade-in class to elements and observe them
document.addEventListener('DOMContentLoaded', () => {
const sections = document.querySelectorAll('section');
const cards = document.querySelectorAll('.detail-card, .skill-category, .project-card');
[...sections, ...cards].forEach(el => {
el.classList.add('fade-in');
observer.observe(el);
});
});
// Animate skill bars
function animateSkillBars() {
const skillBars = document.querySelectorAll('.skill-progress');
skillBars.forEach(bar => {
const width = bar.getAttribute('data-width');
bar.style.width = width + '%';
});
}
// Resume download functionality
const resumeBtn = document.getElementById('resumeBtn');
resumeBtn.addEventListener('click', function(e) {
e.preventDefault();
// Uncomment and modify this when you have your resume file:
const resumeUrl = 'Nihar_Ganesh_Patil_Resume.pdf';
const link = document.createElement('a');
link.href = resumeUrl;
link.download = 'Nihar_Ganesh_Patil_Resume.pdf';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
});
// Update notification function to handle 'info' type
function showNotification(message, type) {
// Remove existing notification
const existingNotification = document.querySelector('.notification');
if (existingNotification) {
existingNotification.remove();
}
// Create notification element
const notification = document.createElement('div');
notification.className = `notification ${type}`;
notification.textContent = message;
// Color based on type
let bgColor;
switch(type) {
case 'success': bgColor = '#4CAF50'; break;
case 'error': bgColor = '#f44336'; break;
case 'info': bgColor = '#2196F3'; break;
default: bgColor = '#333';
}
// Style the notification
notification.style.cssText = `
position: fixed;
top: 20px;
right: 20px;
padding: 15px 20px;
background: ${bgColor};
color: white;
border-radius: 5px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
z-index: 10000;
font-weight: 500;
transform: translateX(100%);
transition: transform 0.3s ease;
max-width: 300px;
`;
document.body.appendChild(notification);
// Animate in
setTimeout(() => {
notification.style.transform = 'translateX(0)';
}, 100);
// Remove after 4 seconds (longer for info messages)
const duration = type === 'info' ? 4000 : 3000;
setTimeout(() => {
notification.style.transform = 'translateX(100%)';
setTimeout(() => {
notification.remove();
}, 300);
}, duration);
}
const contactForm = document.getElementById('contactForm');
contactForm.addEventListener('submit', function(e) {
e.preventDefault();
// Get form data
const formData = new FormData(contactForm);
const name = formData.get('name');
const email = formData.get('email');
const message = formData.get('message');
// Simple validation
if (!name || !email || !message) {
showNotification('Please fill in all fields', 'error');
return;
}
if (!isValidEmail(email)) {
showNotification('Please enter a valid email address', 'error');
return;
}
// Show loading state
const submitBtn = contactForm.querySelector('button[type="submit"]');
const originalText = submitBtn.textContent;
submitBtn.textContent = 'Sending...';
submitBtn.disabled = true;
// Send form data to Formspree
fetch('https://formspree.io/f/xovlwajn', {
method: 'POST',
body: formData,
headers: {
'Accept': 'application/json'
}
})
.then(response => {
if (response.ok) {
showNotification('Message sent successfully! I\'ll get back to you soon.', 'success');
contactForm.reset();
} else {
return response.json().then(data => {
if (data.errors) {
throw new Error(data.errors.map(error => error.message).join(', '));
} else {
throw new Error('Failed to send message');
}
});
}
})
.catch(error => {
console.error('Error:', error);
showNotification('Failed to send message. Please try again or email me directly at niharpatil.codes@gmail.com', 'error');
})
.finally(() => {
// Reset button state
submitBtn.textContent = originalText;
submitBtn.disabled = false;
});
});
// Email validation
function isValidEmail(email) {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}
// Notification system
function showNotification(message, type) {
// Remove existing notification
const existingNotification = document.querySelector('.notification');
if (existingNotification) {
existingNotification.remove();
}
// Create notification element
const notification = document.createElement('div');
notification.className = `notification ${type}`;
notification.textContent = message;
// Style the notification
notification.style.cssText = `
position: fixed;
top: 20px;
right: 20px;
padding: 15px 20px;
background: ${type === 'success' ? '#4CAF50' : '#f44336'};
color: white;
border-radius: 5px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
z-index: 10000;
font-weight: 500;
transform: translateX(100%);
transition: transform 0.3s ease;
`;
document.body.appendChild(notification);
// Animate in
setTimeout(() => {
notification.style.transform = 'translateX(0)';
}, 100);
// Remove after 3 seconds
setTimeout(() => {
notification.style.transform = 'translateX(100%)';
setTimeout(() => {
notification.remove();
}, 300);
}, 3000);
}
// Parallax effect for hero section
window.addEventListener('scroll', () => {
const scrolled = window.pageYOffset;
const hero = document.querySelector('.hero');
const heroContent = document.querySelector('.hero-content');
if (hero && heroContent) {
heroContent.style.transform = `translateY(${scrolled * 0.5}px)`;
}
});
// Add active nav link based on scroll position
window.addEventListener('scroll', () => {
const sections = document.querySelectorAll('section');
const navLinks = document.querySelectorAll('.nav-link');
let current = '';
sections.forEach(section => {
const sectionTop = section.offsetTop;
const sectionHeight = section.clientHeight;
if (window.pageYOffset >= sectionTop - 200) {
current = section.getAttribute('id');
}
});
navLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === `#${current}`) {
link.classList.add('active');
}
});
});
// Add CSS for active nav link
const style = document.createElement('style');
style.textContent = `
.nav-link.active {
color: #667eea;
}
.nav-link.active::after {
width: 100%;
}
`;
document.head.appendChild(style);
// Project card hover effects
document.querySelectorAll('.project-card').forEach(card => {
card.addEventListener('mouseenter', function() {
this.style.transform = 'translateY(-10px) scale(1.02)';
});
card.addEventListener('mouseleave', function() {
this.style.transform = 'translateY(0) scale(1)';
});
});
// Add loading animation
window.addEventListener('load', () => {
const loader = document.createElement('div');
loader.className = 'loader';
loader.innerHTML = `
<div class="loader-spinner"></div>
`;
const loaderStyle = document.createElement('style');
loaderStyle.textContent = `
.loader {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: linear-gradient(135deg, #0D0D0D, #2B2B2B);
display: flex;
justify-content: center;
align-items: center;
z-index: 10000;
opacity: 1;
transition: opacity 0.5s ease;
}
.loader-spinner {
width: 50px;
height: 50px;
border: 3px solid rgba(255, 255, 255, 0.3);
border-top: 3px solid white;
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.loader.fade-out {
opacity: 0;
pointer-events: none;
}
`;
document.head.appendChild(loaderStyle);
document.body.appendChild(loader);
// Remove loader after a short delay
setTimeout(() => {
loader.classList.add('fade-out');
setTimeout(() => {
loader.remove();
loaderStyle.remove();
}, 500);
}, 1000);
});
// Initialize animations when DOM is loaded
document.addEventListener('DOMContentLoaded', () => {
// Add stagger animation to hero elements
const heroElements = document.querySelectorAll('.profile-container, .hero-title, .typing-container, .hero-subtitle, .hero-buttons');
heroElements.forEach((el, index) => {
el.style.animationDelay = `${index * 0.2}s`;
});
// Add hover effects to buttons
document.querySelectorAll('.btn').forEach(btn => {
btn.addEventListener('mouseenter', function() {
this.style.transform = 'translateY(-3px)';
});
btn.addEventListener('mouseleave', function() {
this.style.transform = 'translateY(0)';
});
});
});