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

130
Visualizações
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 à 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