Skip to content

Commit cc00a47

Browse files
committed
fix: adjust track scroll offset
1 parent 6441be8 commit cc00a47

2 files changed

Lines changed: 40 additions & 6 deletions

File tree

  • src/sites/tari-dot-com/pages/HomePage/sections/EcosystemSection/components/Community

src/sites/tari-dot-com/pages/HomePage/sections/EcosystemSection/components/Community/Track.tsx

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,45 @@
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';
412
import BlockchainCapital from './images/blockchain_capital.png';
513
import ParisHilton from './images/paris_hilton.png';
614
import GEAZY from './images/geazy.png';
715
import GMoney from './images/gmoney.png';
816
import Loomdart from './images/loomdart.png';
917
import 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+
1122
export 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,

src/sites/tari-dot-com/pages/HomePage/sections/EcosystemSection/components/Community/styles.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { motion } from 'framer-motion';
22
import styled from 'styled-components';
33

4+
export const TRACK_GAP_SIZE_MOBILE = 20;
5+
export const TRACK_GAP_SIZE_DESKTOP = 62;
6+
47
export const Wrapper = styled(motion.div)`
58
width: 100%;
69
padding-top: 40px;
@@ -52,15 +55,15 @@ export const TrackWidth = styled.div`
5255
export const Track = styled(motion.div)`
5356
display: flex;
5457
align-items: center;
55-
gap: 62px;
58+
gap: ${TRACK_GAP_SIZE_DESKTOP}px;
5659
5760
min-width: max-content;
5861
59-
padding-left: 62px;
62+
padding-left: ${TRACK_GAP_SIZE_DESKTOP}px;
6063
6164
@media (max-width: 768px) {
62-
gap: 20px;
63-
padding-left: 20px;
65+
gap: ${TRACK_GAP_SIZE_MOBILE}px;
66+
padding-left: ${TRACK_GAP_SIZE_MOBILE}px;
6467
}
6568
`;
6669

0 commit comments

Comments
 (0)