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

103
Visualizações
scrollLeft does not update consistently with mouse move event

I have a demo code here: https://codesandbox.io/s/modest-bird-j4jxt7

When I press and hold the red button, then scroll back and forth continuously, the image slider above doesn't move. It just starts moving when I stop moving the red button.

Here I'm using the mouse move event to update the scrollLeft of the slider above. However, I don't know why scrollLeft is only updated after I stop the mouse move event.

I want the image slider to be moved at the same time as the movement of the red button. Do you guys have any ideas for what the problem is and if there is a way to fix it?

Thank you so much for reading!

 const handleMouseMove = (e) => {
    const positionLeft = getPosition(e);
    setPositionLeft(positionLeft);

    const sliderElement = sliderRef.current;
    const sliderBarElement = sliderBarRef.current;
    const sliderBarWidth = sliderBarElement?.offsetWidth;
    const contentWidth = sliderElement?.scrollWidth;
    const viewableRatio = sliderBarWidth / contentWidth;
    const sliderPosition = positionLeft / viewableRatio;

    // The problem is here
    sliderElement.scrollLeft = sliderPosition;
  };
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