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

274
Visualizações
How To Control Scroll Distance?

I'm trying to create the following scroll behavior (in React): each individual 'tick' of the scrollwheel scrolls in multiples of 100 pixels (across browser/OS).

My approach: add a scroll event-handler to the listbox to scroll 100 pixels.

I used onWheel and Element.scrollBy():

onWheel={(event) => {
  event.currentTarget.scrollBy({
    top: Math.sign(event.deltaY) * 100, // 100 pixels in the right direction
    behavior: 'smooth',
  });
}}

https://codesandbox.io/s/modest-lichterman-3iu0r

There are two issues:

  1. Both the user scroll AND the JavaScript scroll execute, and trying to prevent-default on the event doesn't work.
  2. The behavior: 'smooth' animation makes trying to scroll fast extremely slow. I couldn't find how to change the duration of the animation.

I found this Stack Overflow question (and several similar ones), but am not sure how I would apply the answers to this problem.

Thank you!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The functionality I was searching for can be provided via CSS scroll snapping (a browser implemented feature).

CSS Scroll Snap is a module of CSS that introduces scroll snap positions, which enforce the scroll positions that a scroll container’s scrollport may end at after a scrolling operation has completed.

MDN

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