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

133
Views
How to dispatch wheel or scroll event to window using jQuery/JavaScript

I have this case where i wan't to control if the browser window should be scrolled, or if a scrollable div content should be scrolled using mousewheel (in the same scroll event).

Like this:

$('#scrollablediv')[0].addEventListener('wheel', function(e) {
    
    /* try to scroll the browser window instead of the div */
    if (someCondition) {
        e.preventDefault();

        /* this doesn't work */
        var event = jQuery.Event('wheel', {deltaY: e.deltaY} );
        $('html, body').trigger(event);
    }

},{ passive: false }); /* passive: false so i can use e.preventDefault() */

Unfortunately, this doesn't seem to work.

Also, i doesn't wan't to use Window.scrollBy() or Window.scrollTo() because the scroll feels mechanic. It must be a smooth scroll, like the original wheel event.

Note:

I have also tested a solution where i'm changing overflow-y: hidden to overflow-y: scroll using a class, but this requires the visitor to stop scrolling, and starting a new scroll event for it to work. Solution must work using the same scroll event.

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!