// ============================================================ // STEP sas — JavaScript principale // ============================================================ document.addEventListener('DOMContentLoaded', function () { // --- Hamburger menu --- const toggle = document.querySelector('.nav-toggle'); const nav = document.querySelector('nav'); if (toggle && nav) { toggle.addEventListener('click', () => { nav.classList.toggle('open'); const isOpen = nav.classList.contains('open'); toggle.setAttribute('aria-expanded', isOpen); }); // chiudi menu cliccando un link nav.querySelectorAll('a').forEach(link => { link.addEventListener('click', () => nav.classList.remove('open')); }); } // --- Evidenzia voce di menu attiva in base all'URL --- const path = window.location.pathname.split('/').pop() || 'index.html'; document.querySelectorAll('nav a').forEach(a => { const href = a.getAttribute('href').split('/').pop() || 'index.html'; if (href === path) a.classList.add('active'); }); // --- Carosello generico --- document.querySelectorAll('.carousel-wrapper').forEach(wrapper => { const track = wrapper.querySelector('.carousel-track'); const btnPrev = wrapper.querySelector('.carousel-btn.prev'); const btnNext = wrapper.querySelector('.carousel-btn.next'); if (!track) return; const items = track.children; let current = 0; const visible = getVisibleCount(); let autoTimer = null; function getVisibleCount () { return window.innerWidth < 600 ? 2 : window.innerWidth < 900 ? 3 : 4; } function getItemWidth () { if (!items.length) return 0; const style = window.getComputedStyle(track); const gap = parseFloat(style.gap) || 30; return items[0].offsetWidth + gap; } function maxIndex () { return Math.max(0, items.length - getVisibleCount()); } function goTo (idx) { current = Math.max(0, Math.min(idx, maxIndex())); track.style.transform = `translateX(-${current * getItemWidth()}px)`; if (btnPrev) btnPrev.disabled = current === 0; if (btnNext) btnNext.disabled = current >= maxIndex(); } if (btnPrev) btnPrev.addEventListener('click', () => goTo(current - 1)); if (btnNext) btnNext.addEventListener('click', () => goTo(current + 1)); // Auto-scorrimento function startAuto () { autoTimer = setInterval(() => { goTo(current >= maxIndex() ? 0 : current + 1); }, 3500); } wrapper.addEventListener('mouseenter', () => clearInterval(autoTimer)); wrapper.addEventListener('mouseleave', startAuto); window.addEventListener('resize', () => goTo(0)); goTo(0); startAuto(); }); // --- Form contatti: validazione e invio simulato --- const form = document.getElementById('contact-form'); if (form) { form.addEventListener('submit', function (e) { e.preventDefault(); const fields = ['nome', 'email', 'oggetto', 'messaggio']; let valid = true; fields.forEach(id => { const el = document.getElementById(id); if (el) { el.style.borderColor = el.value.trim() === '' ? '#c00' : ''; if (el.value.trim() === '') valid = false; } }); const emailEl = document.getElementById('email'); if (emailEl && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(emailEl.value)) { emailEl.style.borderColor = '#c00'; valid = false; } if (valid) { const successBox = document.getElementById('form-success'); if (successBox) { form.style.display = 'none'; successBox.style.display = 'block'; } } }); // rimuovi bordo rosso alla digitazione form.querySelectorAll('input, textarea').forEach(el => { el.addEventListener('input', () => el.style.borderColor = ''); }); } // --- Hover sull'immagine soluzioni (bulb) --- const bulbImg = document.getElementById('bulb-img'); if (bulbImg) { const src = bulbImg.src; const hoverSrc = bulbImg.dataset.hover; if (hoverSrc) { bulbImg.addEventListener('mouseenter', () => bulbImg.src = hoverSrc); bulbImg.addEventListener('mouseleave', () => bulbImg.src = src); } } // --- Animazione scroll (fade-in per le card) --- const observer = new IntersectionObserver((entries) => { entries.forEach(entry => { if (entry.isIntersecting) { entry.target.classList.add('visible'); observer.unobserve(entry.target); } }); }, { threshold: 0.12 }); document.querySelectorAll('.servizio-card, .fade-in').forEach(el => { el.classList.add('hidden-anim'); observer.observe(el); }); });