CoolFace
Apppublic

camelDeep/codecraft-junior-adventure

sourceHugging Faceupdated 11mo agoView on Hugging Face
0likes
script.js61 linesDownload Raw Back to root
1// Intersection Observer for section animations2document.addEventListener('DOMContentLoaded', () => {3    const sections = document.querySelectorAll('section');4    5    const observerOptions = {6        threshold: 0.1,7        rootMargin: '0px 0px -50px 0px'8    };9    10    const sectionObserver = new IntersectionObserver((entries, observer) => {11        entries.forEach(entry => {12            if (entry.isIntersecting) {13                entry.target.classList.add('visible');14                observer.unobserve(entry.target);15            }16        });17    }, observerOptions);18    19    sections.forEach(section => {20        sectionObserver.observe(section);21    });22// Smooth scroll for anchor links - Version améliorée avec console.log pour debug23document.querySelectorAll('a[href^="#"]').forEach(anchor => {24    anchor.addEventListener('click', function(e) {25        e.preventDefault();26        const targetId = this.getAttribute('href');27        console.log('Clic sur le lien vers:', targetId); // Debug28        29        if (targetId === '#') return;30        31        const targetElement = document.querySelector(targetId);32        if (targetElement) {33            console.log('Élément trouvé:', targetElement); // Debug34            window.scrollTo({35                top: targetElement.offsetTop - 80,36                behavior: 'smooth'37            });38            39            // Ajout pour fermer le menu mobile si ouvert40            const mobileMenu = document.querySelector('custom-navbar').shadowRoot.querySelector('ul.open');41            if (mobileMenu) {42                mobileMenu.classList.remove('open');43                const menuBtn = document.querySelector('custom-navbar').shadowRoot.querySelector('.mobile-menu-btn i');44                menuBtn.setAttribute('data-feather', 'menu');45                feather.replace();46            }47        } else {48            console.warn('Élément non trouvé:', targetId); // Debug49        }50    });51});52// Form submission handler53    const contactForm = document.querySelector('#contact form');54    if (contactForm) {55        contactForm.addEventListener('submit', (e) => {56            e.preventDefault();57            alert('Merci pour votre message! Je vous répondrai dès que possible.');58            contactForm.reset();59        });60    }61});