Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

109
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!