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

110
Visualizações
Scrollable horizontal overflow not firing when scrolling without moving mouse

I'm currently trying to build a scrollable horizontal overflow that is scrollable with mouse wheel when the user arrives at this element while scrolling the page. Only issue I'm having is that, if the user scrolls without moving the cursor, the scroll won't fire as it is not understood that the mouse is over the element with the wheel event. Moving the mouse at least one pixel once on the element does fire the handler though.

Any way to fix this?

const scrollable = document.querySelector('main')

scrollable.addEventListener('wheel', e => {
    e.preventDefault()
    scrollable.scrollLeft += e.deltaY
})
html,
body {
    margin: 0;
    font-family: sans-serif;
}

.vertical-section {
    height: 800px;
    display: flex;
    align-items: center;
    justify-content: center;
}

main {
    overflow-x: hidden;
    display: flex;
    top: 0;
}

h1 {
    margin: 0;
    padding: 0;
}

section {
    min-width: 100vw;
    height: 200px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 4ch;
}

section:nth-child(even) {
    background-color: teal;
    color: white;
}
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <link rel="stylesheet" href="styles.css" />
        <title>Document</title>
    </head>
    <body>
        <div class="vertical-section" style="background-color: antiquewhite">
            Content above
        </div>
        <div class="sticky-container">
            <main>
                <section>
                    <h1>Slide 1</h1>
                </section>
                <section>
                    <h1>Slide 2</h1>
                </section>
                <section>
                    <h1>Slide 3</h1>
                </section>
                <section>
                    <h1>The End</h1>
                </section>
            </main>
        </div>
        <div class="vertical-section" style="background-color: brown">
            Content Below
        </div>
        <script src="script.js"></script>
    </body>
</html>

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