Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

172
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!