Estoy siguiendo un tutorial y estoy cerca del final, ¿mi animación de desplazamiento no parece funcionar? ¿Alguien podría señalar si tengo algún error con mi javascript ya que soy bastante nuevo?
https://www.youtube.com/watch?v=afaqr875gUE&t=486s (en caso de que te preguntes cuál era el tutorial)
código:
document.lastScrollPosition = 0; document.lastCentered = 0; document.onWayTo = null; document.addEventListener('scroll', listener: () => { const direction = window.pageYOffset - document.lastScrollPosition > 0 'down' : 'up'; const sections = [...document.querySelectorAll('selection')]; if(document.onWayTo === null) { const destIndex = direction === 'up' ? document.lastCentered - 1 : document.lastCentered + 1; if(destIndex >= 0 && destIndex < sections.length) { console.log({destIndex,direction}); document.onWayTo = destIndex; window.scroll(x: 0, sections[destIndex].offsetTop); } } sections.forEach((section,index : number) => { if(window.pageYOffset === section.offsetTop) { document.lastCentered = index; section.className = 'action'; if (document.onWayTo === index) { document.onWayTo = null; } } else{ section.className = ''; } }) document.lastScrollPosition = window.pageYOffset; })