Spaces:
Running
Running
File size: 1,764 Bytes
2e41dd0 | 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 | // Smooth scroll for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const targetId = this.getAttribute('href');
if (targetId === '#') return;
const targetElement = document.querySelector(targetId);
if (targetElement) {
window.scrollTo({
top: targetElement.offsetTop - 100,
behavior: 'smooth'
});
}
});
});
// Form submission handler
const contactForm = document.querySelector('form');
if (contactForm) {
contactForm.addEventListener('submit', async (e) => {
e.preventDefault();
const formData = new FormData(contactForm);
const data = Object.fromEntries(formData);
try {
// Here you would typically send the data to your backend
console.log('Form submitted:', data);
// Show success message
alert('Thank you for your message! I will get back to you soon.');
contactForm.reset();
} catch (error) {
console.error('Error submitting form:', error);
alert('There was an error sending your message. Please try again later.');
}
});
}
// 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('animate-fadeIn');
}
});
}, observerOptions);
document.querySelectorAll('[data-observe]').forEach(el => {
observer.observe(el);
}); |