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

174
Visualizações
Carousel using React hook not sliding smoothly on Mobile not Desktop

Code and Result Link

I tried to make a carousel using React hooks and succeed on Desktop browser. But I don't know why it doesn't perform as the same on Mobile browser. It moves like laggy and not soft and smooth.

Full screen for output

you can check any of links to check my problems on Mobile browser. if you guy know why it performs differently on mobile and if you guys know the solution for this, please tell me..

...

const onMouseUp = useCallback(e => {
    const currentPosition = e.clientX || e.changedTouches[0].clientX
    const delta = (currentPosition - swipeInfo.originX) / ref.current.clientWidth * 100
    setSwipeInfo(state => ({
      ...state,
      isSwiping: false,
      transitionX: 0
    }))
    if ( delta < -SENSITIVITY ) {
      if (current === LAST_SLIDES) return
      ref.current.style.transition = 'all 0.3s ease-in-out'
      ref.current.style.transform = `translateX(-${current}00%)`
      setCurrent(current + 1)
    } else if ( delta > SENSITIVITY) {
      if (current === FIRST_SLIDES) return
      ref.current.style.transition = 'all 0.3s ease-in-out'
      ref.current.style.transform = `translateX(-${current - 2}00%)`
      setCurrent(current - 1)
    } else {
      ref.current.style.transition = 'all 0.3s ease-in-out'
    }
  }, [current, swipeInfo.originX])
  
  useEffect(() => {
    if(swipeInfo.isSwiping) {
      document.addEventListener("mousemove", onMouseMove, {capture: true})
      document.addEventListener("mouseleave", onMouseUp, {capture: true})
      document.addEventListener("mouseup", onMouseUp, {capture: true})
      document.addEventListener("touchmove", onTouchMove, {capture: true})
      document.addEventListener("touchend", onMouseUp, {capture: true})
    }
    return () => {
      document.removeEventListener("mousemove", onMouseMove, {capture: true})
      document.removeEventListener("mouseleave", onMouseUp, {capture: true})
      document.removeEventListener("mouseup", onMouseUp, {capture: true})
      document.removeEventListener("touchmove", onTouchMove, {capture: true})
      document.removeEventListener("touchend", onMouseUp, {capture: true})
    }
  }, [swipeInfo.isSwiping])


...

And I didn't write the full codes here bcuz it seems like CSS problems not react and javascript problems

thank you for reading!

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