document.addEventListener('DOMContentLoaded', function() { // Smooth scrolling pour les liens de navigation const navLinks = document.querySelectorAll('nav a[href^="#"]'); navLinks.forEach(link => { link.addEventListener('click', function(e) { e.preventDefault(); const targetId = this.getAttribute('href'); const targetSection = document.querySelector(targetId); if (targetSection) { const headerHeight = document.querySelector('header').offsetHeight; const targetPosition = targetSection.offsetTop - headerHeight; window.scrollTo({ top: targetPosition, behavior: 'smooth' }); } }); }); // Gestion du formulaire de contact const contactForm = document.getElementById('contactForm'); contactForm.addEventListener('submit', function(e) { e.preventDefault(); const formData = new FormData(this); const name = formData.get('name'); const email = formData.get('email'); const message = formData.get('message'); // Validation simple if (!name || !email || !message) { alert('Veuillez remplir tous les champs obligatoires.'); return; } // Validation email const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; if (!emailRegex.test(email)) { alert('Veuillez entrer une adresse email valide.'); return; } // Simulation d'envoi (en réalité, vous devriez envoyer à un serveur) alert(`Merci ${name} ! Votre message a été reçu. Nous vous contacterons bientôt à l'adresse ${email}.`); // Réinitialiser le formulaire this.reset(); }); // Animation au scroll pour les cartes de services 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); // Observer les cartes de services const serviceCards = document.querySelectorAll('.service-card'); serviceCards.forEach(card => { card.style.opacity = '0'; card.style.transform = 'translateY(20px)'; card.style.transition = 'opacity 0.6s ease, transform 0.6s ease'; observer.observe(card); }); // Effet de highlight sur la navigation active window.addEventListener('scroll', function() { const sections = document.querySelectorAll('section[id]'); const navLinks = document.querySelectorAll('nav a[href^="#"]'); let currentSection = ''; const headerHeight = document.querySelector('header').offsetHeight; sections.forEach(section => { const sectionTop = section.offsetTop - headerHeight - 100; const sectionHeight = section.offsetHeight; if (window.scrollY >= sectionTop && window.scrollY < sectionTop + sectionHeight) { currentSection = section.getAttribute('id'); } }); navLinks.forEach(link => { link.classList.remove('active'); if (link.getAttribute('href') === `#${currentSection}`) { link.classList.add('active'); } }); }); });