document.addEventListener('DOMContentLoaded', function() { // Mobile menu toggle const mobileMenuButton = document.querySelector('.md\\:hidden button'); const mobileMenu = document.createElement('div'); mobileMenu.className = 'fixed inset-0 bg-white z-50 flex flex-col items-center justify-center hidden'; mobileMenu.innerHTML = `
`; document.body.appendChild(mobileMenu); mobileMenuButton.addEventListener('click', function() { mobileMenu.classList.remove('hidden'); feather.replace(); }); mobileMenu.querySelector('button').addEventListener('click', function() { mobileMenu.classList.add('hidden'); }); // Smooth scrolling 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) { const headerHeight = document.querySelector('nav').offsetHeight; const targetPosition = targetElement.getBoundingClientRect().top + window.pageYOffset - headerHeight; window.scrollTo({ top: targetPosition, behavior: 'smooth' }); // Close mobile menu if open mobileMenu.classList.add('hidden'); } }); }); // Animate elements when they come into view const animateOnScroll = function() { const elements = document.querySelectorAll('.animate-fade-in'); elements.forEach(element => { const elementPosition = element.getBoundingClientRect().top; const screenPosition = window.innerHeight / 1.3; if (elementPosition < screenPosition) { element.style.opacity = '1'; element.style.transform = 'translateY(0)'; } }); }; // Set initial state for animated elements document.querySelectorAll('.animate-fade-in').forEach(element => { element.style.opacity = '0'; element.style.transform = 'translateY(20px)'; element.style.transition = 'opacity 0.6s ease, transform 0.6s ease'; }); // Run once on load and then on scroll animateOnScroll(); window.addEventListener('scroll', animateOnScroll); // Current year in footer document.querySelector('footer p:first-of-type').innerHTML = `© ${new Date().getFullYear()} L'Églantine. Tous droits réservés.`; // Replace feather icons (already called in HTML but just in case) feather.replace(); });