@@ -33,32 +33,38 @@ function MobilePartnersStrip({
3333} ) {
3434 const innerRef = React . useRef < HTMLDivElement > ( null )
3535 const [ isHovered , setIsHovered ] = React . useState ( false )
36+ const scrollPositionRef = React . useRef ( 0 )
37+ const hasStartedRef = React . useRef ( false )
3638
3739 React . useEffect ( ( ) => {
3840 const inner = innerRef . current
3941 if ( ! inner ) return
4042
4143 let animationId : number
4244 let timeoutId : ReturnType < typeof setTimeout >
43- let scrollPosition = 0
44- const scrollSpeed = 0.08 // pixels per frame - very slow
45- const startDelay = 4000 // wait 4 seconds before starting
45+ const scrollSpeed = 0.15 // pixels per frame
46+ const startDelay = 4000 // wait 4 seconds before starting (first time only)
4647
4748 const animate = ( ) => {
4849 if ( ! isHovered && inner ) {
49- scrollPosition += scrollSpeed
50+ scrollPositionRef . current += scrollSpeed
5051 // Reset when we've scrolled past the first set
51- if ( scrollPosition >= inner . scrollWidth / 2 ) {
52- scrollPosition = 0
52+ if ( scrollPositionRef . current >= inner . scrollWidth / 2 ) {
53+ scrollPositionRef . current = 0
5354 }
54- inner . style . transform = `translateX(${ - scrollPosition } px)`
55+ inner . style . transform = `translateX(${ - scrollPositionRef . current } px)`
5556 }
5657 animationId = requestAnimationFrame ( animate )
5758 }
5859
59- timeoutId = setTimeout ( ( ) => {
60+ if ( ! hasStartedRef . current ) {
61+ timeoutId = setTimeout ( ( ) => {
62+ hasStartedRef . current = true
63+ animationId = requestAnimationFrame ( animate )
64+ } , startDelay )
65+ } else {
6066 animationId = requestAnimationFrame ( animate )
61- } , startDelay )
67+ }
6268
6369 return ( ) => {
6470 clearTimeout ( timeoutId )
0 commit comments