Welcome to WordPress. This is your first post. Edit or delete it, then start writing!

1 Commento. Nuovo commento

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *

Compila questo campo
Compila questo campo
Inserisci un indirizzo email valido.
Devi accettare i termini per procedere

document.addEventListener("DOMContentLoaded", () => { const sections = Array.from(document.querySelectorAll(".scroll-section")); if (sections.length === 0) return; let current = 0; let isScrolling = false; // Aggiorna indice corrente basandosi su quale sezione è visibile const updateCurrentIndex = () => { const scrollTop = window.scrollY || document.documentElement.scrollTop; const viewportHeight = window.innerHeight; const index = Math.round(scrollTop / viewportHeight); if (index !== current) { current = index; } }; const scrollTo = (index) => { if (index < 0 || index >= sections.length) return; sections[index].scrollIntoView({ behavior: "smooth" }); isScrolling = true; setTimeout(() => { isScrolling = false; updateCurrentIndex(); }, 800); }; window.addEventListener("wheel", (e) => { if (isScrolling) return; updateCurrentIndex(); // aggiorna sezione attuale if (e.deltaY > 30 && current < sections.length - 1) { scrollTo(current + 1); } else if (e.deltaY < -30 && current > 0) { scrollTo(current - 1); } }); // touch mobile let startY = 0; window.addEventListener("touchstart", (e) => { startY = e.touches[0].clientY; }); window.addEventListener("touchend", (e) => { if (isScrolling) return; const deltaY = startY - e.changedTouches[0].clientY; updateCurrentIndex(); if (deltaY > 50 && current < sections.length - 1) { scrollTo(current + 1); } else if (deltaY < -50 && current > 0) { scrollTo(current - 1); } }); });