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

185
Visualizações
Scroll function works fast in mac and touchpad

I have a slider and I made a code that goes next and prev with mouse scroll. But it doesn't work well with mac and touchpad. how can I fix it? Can I put some delay or something I tried to use some setTimeout but it didn't work well or I didn't do it right.

$('#body').on('mousewheel', function (event) {
  if (typeof event.originalEvent.wheelDeltaY === 'undefined') {
    console.log("could not find mouse deltas")
  }
  var deltaY = event.originalEvent.wheelDeltaY;
  var scrolledUp = deltaY < 0;
  var scrolledDown = deltaY > 0;
  if (scrolledDown) {
    if (swiper_color.activeIndex > 2) {
      goTop();
      activeIndexToTwo();
    } else {
        swiper_color.slidePrev();
        swiper_image.slidePrev();
        swiper_desc.slidePrev();
        swiper_title.slidePrev();
        swiper_jar.slidePrev();
    }
  }
  if (scrolledUp) {
    if (swiper_color.activeIndex < 2) {
      swiper_color.slideNext();
      swiper_image.slideNext();
      swiper_desc.slideNext();
      swiper_title.slideNext();
      swiper_jar.slideNext();
    } else {
      checkscroll();
    }
  }
});
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I'd recommend throttling the function. You could write a throttle function, or use one from a library like Lodash (Lodash throttle docs)

function yourFn (event) {
  // ... all of your js here
  // ...
}

$('#body').on('mousewheel', _.throttle(yourFn, 100));

The 100(ms) above means your function can only fire every 100ms, feel free to modify the time to your liking.

about 4 years ago · Juan Pablo Isaza Relatório
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