11'use client' ;
22
3- import { TrackWrapper , TrackWidth , Track , Image } from './styles' ;
3+ import { useEffect , useState } from 'react' ;
4+ import {
5+ TrackWrapper ,
6+ TrackWidth ,
7+ Track ,
8+ Image ,
9+ TRACK_GAP_SIZE_DESKTOP ,
10+ TRACK_GAP_SIZE_MOBILE ,
11+ } from './styles' ;
412import BlockchainCapital from './images/blockchain_capital.png' ;
513import ParisHilton from './images/paris_hilton.png' ;
614import GEAZY from './images/geazy.png' ;
715import GMoney from './images/gmoney.png' ;
816import Loomdart from './images/loomdart.png' ;
917import LilWayne from './images/lilwayne.png' ;
1018
19+ const imagesToScroll = [ BlockchainCapital , ParisHilton , GEAZY , GMoney , Loomdart , LilWayne ] ;
20+ const imagesTotalWidth = imagesToScroll . reduce ( ( sum , image ) => sum + image . width , 0 ) ;
21+
1122export default function TrackComponent ( ) {
23+ const [ isMobileViewport , setIsMobileViewport ] = useState ( false ) ;
24+
25+ useEffect ( ( ) => {
26+ const mobileQuery = window . matchMedia ( `(max-width: 768px)` ) ;
27+
28+ const updateViewportMatch = ( ) => {
29+ setIsMobileViewport ( mobileQuery . matches ) ;
30+ } ;
31+
32+ updateViewportMatch ( ) ;
33+ mobileQuery . addEventListener ( 'change' , updateViewportMatch ) ;
34+
35+ return ( ) => {
36+ mobileQuery . removeEventListener ( 'change' , updateViewportMatch ) ;
37+ } ;
38+ } , [ ] ) ;
39+
40+ const gapSize = isMobileViewport ? TRACK_GAP_SIZE_MOBILE : TRACK_GAP_SIZE_DESKTOP ;
41+ const scrollOffset = imagesTotalWidth + imagesToScroll . length * gapSize ;
42+
1243 return (
1344 < TrackWrapper >
1445 < TrackWidth >
@@ -17,7 +48,7 @@ export default function TrackComponent() {
1748 x : '0px' ,
1849 } }
1950 animate = { {
20- x : '-1691px' ,
51+ x : `- ${ scrollOffset } px` ,
2152 transition : {
2253 x : {
2354 repeat : Infinity ,
0 commit comments