-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
339 lines (283 loc) · 10.4 KB
/
Copy pathscript.js
File metadata and controls
339 lines (283 loc) · 10.4 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
// Mobile Menu Toggle
const hamburger = document.querySelector('.hamburger');
const navMenu = document.querySelector('.nav-menu');
const navLinks = document.querySelectorAll('.nav-link');
hamburger.addEventListener('click', () => {
hamburger.classList.toggle('active');
navMenu.classList.toggle('active');
});
navLinks.forEach(link => {
link.addEventListener('click', () => {
hamburger.classList.remove('active');
navMenu.classList.remove('active');
});
});
// Smooth Scrolling
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 Scroll Effect
let lastScroll = 0;
const navbar = document.querySelector('.navbar');
window.addEventListener('scroll', () => {
const currentScroll = window.pageYOffset;
if (currentScroll > 100) {
navbar.style.boxShadow = '0 1px 3px rgba(0, 0, 0, 0.05)';
} else {
navbar.style.boxShadow = '0 1px 3px rgba(0, 0, 0, 0.03)';
}
lastScroll = currentScroll;
});
// Scroll Animations
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -100px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
}
});
}, observerOptions);
// Observe elements for scroll animations
document.addEventListener('DOMContentLoaded', () => {
const animateElements = document.querySelectorAll('.about-content, .skill-card, .project-card, .contact-content, .stat-item, .progress-item');
animateElements.forEach(el => {
el.classList.add('fade-in');
observer.observe(el);
});
});
// Progress Bar Animation
const progressBars = document.querySelectorAll('.progress-fill');
const animateProgressBars = () => {
progressBars.forEach(bar => {
const progress = bar.getAttribute('data-progress');
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
bar.style.width = progress + '%';
observer.unobserve(entry.target);
}
});
}, { threshold: 0.5 });
observer.observe(bar);
});
};
animateProgressBars();
// Function to show form status messages
function showStatus(message, type) {
const formStatus = document.getElementById('form-status');
if (formStatus) {
formStatus.textContent = message;
formStatus.className = `form-status ${type}`;
// Remove status after 5 seconds
setTimeout(() => {
formStatus.textContent = '';
formStatus.className = 'form-status';
}, 5000);
}
}
// Form Submission to Backend (Gmail SMTP)
document.addEventListener('DOMContentLoaded', function() {
const contactForm = document.getElementById('contact-form');
const formStatus = document.getElementById('form-status');
const submitBtn = document.getElementById('submit-btn');
// Backend API endpoint
// For local development: 'http://localhost:3000'
// For Vercel production: '/api' (relative path works automatically)
const API_URL = window.location.hostname === 'localhost'
? 'http://localhost:3000'
: '/api';
if (contactForm) {
const handleSubmit = async (e) => {
e.preventDefault();
// Get form data
const name = document.getElementById('name').value.trim();
const email = document.getElementById('email').value.trim();
const subject = document.getElementById('subject').value.trim();
const message = document.getElementById('message').value.trim();
// Validation
if (!name || !email || !subject || !message) {
showStatus('Please fill in all fields.', 'error');
return;
}
// Email validation
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(email)) {
showStatus('Please enter a valid email address.', 'error');
return;
}
// Disable submit button
submitBtn.disabled = true;
submitBtn.textContent = 'Sending...';
formStatus.textContent = '';
try {
// Send form data to backend
const endpoint = API_URL === '/api' ? '/api/send-email' : `${API_URL}/send-email`;
const response = await fetch(endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
name: name,
email: email,
subject: subject,
message: message
})
});
const data = await response.json();
if (response.ok) {
showStatus('Thank you for your message! I will get back to you soon.', 'success');
contactForm.reset();
} else {
showStatus(data.error || 'Sorry, there was an error sending your message. Please try again.', 'error');
}
} catch (error) {
console.error('Error sending email:', error);
showStatus('Sorry, there was an error sending your message. Please make sure the server is running or contact me directly at contact@settlerep.com', 'error');
} finally {
submitBtn.disabled = false;
submitBtn.textContent = 'Send Message';
}
};
contactForm.addEventListener('submit', handleSubmit);
}
});
// Active Nav Link on Scroll
const sections = document.querySelectorAll('section[id]');
const activateNavLink = () => {
const scrollY = window.pageYOffset;
sections.forEach(section => {
const sectionHeight = section.offsetHeight;
const sectionTop = section.offsetTop - 100;
const sectionId = section.getAttribute('id');
const navLink = document.querySelector(`.nav-link[href="#${sectionId}"]`);
if (scrollY > sectionTop && scrollY <= sectionTop + sectionHeight) {
navLinks.forEach(link => link.classList.remove('active'));
if (navLink) {
navLink.classList.add('active');
}
}
});
};
window.addEventListener('scroll', activateNavLink);
// Parallax Effect for Hero Section
window.addEventListener('scroll', () => {
const scrolled = window.pageYOffset;
const hero = document.querySelector('.hero');
if (hero && scrolled < window.innerHeight) {
hero.style.transform = `translateY(${scrolled * 0.5}px)`;
hero.style.opacity = 1 - scrolled / window.innerHeight;
}
});
// Typing Effect (Optional Enhancement)
const typingEffect = (element, text, speed = 100) => {
let i = 0;
element.textContent = '';
const type = () => {
if (i < text.length) {
element.textContent += text.charAt(i);
i++;
setTimeout(type, speed);
}
};
type();
};
// Add hover effect to project cards
const projectCards = document.querySelectorAll('.project-card');
projectCards.forEach(card => {
card.addEventListener('mouseenter', () => {
card.style.transform = 'translateY(-10px) scale(1.02)';
});
card.addEventListener('mouseleave', () => {
card.style.transform = 'translateY(0) scale(1)';
});
});
// Add ripple effect to buttons
const buttons = document.querySelectorAll('.btn');
buttons.forEach(button => {
button.addEventListener('click', function(e) {
const ripple = document.createElement('span');
const rect = this.getBoundingClientRect();
const size = Math.max(rect.width, rect.height);
const x = e.clientX - rect.left - size / 2;
const y = e.clientY - rect.top - size / 2;
ripple.style.width = ripple.style.height = size + 'px';
ripple.style.left = x + 'px';
ripple.style.top = y + 'px';
ripple.classList.add('ripple');
this.appendChild(ripple);
setTimeout(() => {
ripple.remove();
}, 600);
});
});
// Add CSS for ripple effect dynamically
const style = document.createElement('style');
style.textContent = `
.btn {
position: relative;
overflow: hidden;
}
.ripple {
position: absolute;
border-radius: 50%;
background: rgba(255, 255, 255, 0.6);
transform: scale(0);
animation: ripple-animation 0.6s ease-out;
pointer-events: none;
}
@keyframes ripple-animation {
to {
transform: scale(4);
opacity: 0;
}
}
.nav-link.active {
color: var(--primary-color);
}
.nav-link.active::after {
width: 100%;
}
`;
document.head.appendChild(style);
// Prevent navigation on disabled links (href="#")
document.addEventListener('DOMContentLoaded', () => {
// Disable project links with href="#"
const disabledProjectLinks = document.querySelectorAll('.project-link[href="#"]');
disabledProjectLinks.forEach(link => {
link.addEventListener('click', (e) => {
e.preventDefault();
e.stopPropagation();
});
});
// Disable social links with href="#"
const disabledSocialLinks = document.querySelectorAll('.social-link[href="#"]');
disabledSocialLinks.forEach(link => {
link.addEventListener('click', (e) => {
e.preventDefault();
e.stopPropagation();
});
});
});
// Initialize on page load
window.addEventListener('load', () => {
// Add loaded class to body for any load animations
document.body.classList.add('loaded');
// Trigger initial animations
const heroText = document.querySelector('.animated-text');
if (heroText) {
heroText.style.opacity = '1';
}
});