Skip to content
This repository was archived by the owner on Feb 15, 2025. It is now read-only.

Commit 95a5cc3

Browse files
committed
made more feature carousel endless
1 parent 6cb4287 commit 95a5cc3

File tree

1 file changed

+17
-21
lines changed
  • src/_pages/LandingPage/components/OtherFeaturesView/components/Cards

1 file changed

+17
-21
lines changed

src/_pages/LandingPage/components/OtherFeaturesView/components/Cards/index.tsx

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ const Cards: React.FC<Props> = (props) => {
3030
const handlers = useSwipeable({
3131
onSwipedLeft: () => {
3232
if (index < cards.length - 1) setIndex(index + 1);
33+
else setIndex(0);
3334
},
3435
onSwipedRight: () => {
3536
if (index > 0) setIndex(index - 1);
37+
else setIndex(cards.length - 1);
3638
},
3739
preventDefaultTouchmoveEvent: true,
3840
trackMouse: true,
@@ -49,16 +51,8 @@ const Cards: React.FC<Props> = (props) => {
4951
} => {
5052
const { width } = cardDimensions;
5153

52-
if (i - 3 >= index) {
53-
return {
54-
translateX: width / 2 + width / 40,
55-
zIndex: -1,
56-
opacity: 0,
57-
scale: 0.75,
58-
};
59-
}
60-
61-
if (i - 2 === index) {
54+
// Card 2 Left
55+
if (i - 2 === index || i + (cards.length - 2) === index) {
6256
return {
6357
translateX: width / 2 + width / 40,
6458
zIndex: 0,
@@ -67,7 +61,8 @@ const Cards: React.FC<Props> = (props) => {
6761
};
6862
}
6963

70-
if (i - 1 === index) {
64+
// Card 1 Left
65+
if (i - 1 === index || i + (cards.length - 1) === index) {
7166
return {
7267
translateX: width / 4,
7368
zIndex: 1,
@@ -76,6 +71,7 @@ const Cards: React.FC<Props> = (props) => {
7671
};
7772
}
7873

74+
// Centered Card
7975
if (i === index) {
8076
return {
8177
translateX: 0,
@@ -85,7 +81,8 @@ const Cards: React.FC<Props> = (props) => {
8581
};
8682
}
8783

88-
if (i + 1 === index) {
84+
// Card 1 Right
85+
if (i + 1 === index || i - (cards.length - 1) === index) {
8986
return {
9087
translateX: -width / 4,
9188
zIndex: 1,
@@ -94,7 +91,8 @@ const Cards: React.FC<Props> = (props) => {
9491
};
9592
}
9693

97-
if (i + 2 === index) {
94+
// Card 2 Right
95+
if (i + 2 === index || i - (cards.length - 2) === index) {
9896
return {
9997
translateX: -width / 2 - width / 40,
10098
zIndex: 0,
@@ -103,14 +101,12 @@ const Cards: React.FC<Props> = (props) => {
103101
};
104102
}
105103

106-
if (i + 3 <= index) {
107-
return {
108-
translateX: -width / 2 - width / 40,
109-
zIndex: -1,
110-
opacity: 0,
111-
scale: 0.75,
112-
};
113-
}
104+
return {
105+
translateX: 0,
106+
zIndex: -1,
107+
opacity: 0,
108+
scale: 0.75,
109+
};
114110
},
115111
[index, cardDimensions, windowWidth]
116112
);

0 commit comments

Comments
 (0)