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

129
Vistas
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
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