Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

195
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda