Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

188
Vistas
How can I get Scroll Snap working with JS scroll event listener?

I am working on this project where I need both, a scroll listener and scroll-snapping, so I can use a mouse wheel with a horizontal full-screen container that snaps between sections. (When the user scrolls vertically, it scrolls on the X-axis instead.)

I can get both of these to work separately, but not together. When I enable the JS on scroll function it prevents the scroll snapping from working.

I tried everything I know, tried changing other containers' height/overflow properties and tried targeting other elements than body or window. What would be the best workaround be?

The snippet here is adjusted to work with scroll listener at the moment

const scrollContainer = document.querySelector('.container');

scrollContainer.addEventListener('wheel', (e) => {
    e.preventDefault();
    scrollContainer.scrollLeft += e.deltaY;
});
* {
  margin: 0;
}

.container {
  display: flex;
  overflow-x: scroll;
  /*scroll-snap-type: x mandatory;*/
}

section {
  height: 100vh;
  width: 300vw;
  min-width: 100vw;
  /*scroll-snap-align: start;*/
}

#section1 {
  background: red;
}

#section2 {
  background: yellow;
}

#section3 {
  background: blue;
}
<html>
  <div class="container">
    <section id="section1"></section>
    <section id="section2"></section>
    <section id="section3"></section>
  </div>
</html>
  

When i add the following code to enable scroll snap. It stops the wheel event listener from functioning correctly.

.container {
  scroll-snap-type: x mandatory;
}

section {
  scroll-snap-align: start;
}
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda