Skip to content

Commit 40b42bc

Browse files
mobile, border, and infinite scroll (#72)
* mobile, border, and infinite scroll * typo fix --------- Co-authored-by: Anjali Jay Jain <[email protected]>
1 parent 4ef50b7 commit 40b42bc

File tree

3 files changed

+31
-13
lines changed

3 files changed

+31
-13
lines changed

app/(pages)/(index-page)/_components/SandCastle.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function WhatIsHackDavisText() {
6363
</h1>
6464
<p className="text-base sm:text-xl md:text-2xl lg:text-3xl 2xl:text-5xl">
6565
is one of the
66-
<strong> largest collegiate hackathon </strong> in California, where
66+
<strong> largest collegiate hackathons </strong> in California, where
6767
over 850 students, creators, and leaders come together to{' '}
6868
<strong>create for social good</strong>.
6969
</p>

app/(pages)/about-us/_components/Recap/Recap.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default function Recap() {
88
<div className="w-full md:w-[90%]">
99
<h2 className="text-2xl font-bold">HackDavis 2024 Recap</h2>
1010
</div>
11-
<div className="flex flex-col gap-12 sm:items-center md:flex-row md:gap-4">
11+
<div className="flex flex-col gap-12 sm:items-center md:gap-4 min-[900px]:flex-row">
1212
<div className="w-full">
1313
<RecapCarousel />
1414
</div>

app/(pages)/about-us/_components/Recap/recap_carousel.tsx

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,29 @@ export default function RecapCarousel() {
3737
const [position, setPosition] = useState(2);
3838
const [touchStart, setTouchStart] = useState(0);
3939
const [touchEnd, setTouchEnd] = useState(0);
40+
const [xOffset, setXOffset] = useState(-250);
4041

4142
useEffect(() => {
4243
const interval = setInterval(() => {
43-
setPosition((prev) => (prev >= 5 ? 1 : prev + 1));
44-
}, 5000); // Increased to 5 seconds for slower rotation
44+
setPosition((prev) => (prev + 1) % images.length);
45+
}, 5000);
4546

46-
return () => clearInterval(interval);
47+
// Handle the initial window width and subsequent resizes
48+
const handleResize = () => {
49+
setXOffset(window.innerWidth < 400 ? -100 : -250);
50+
};
51+
52+
// Set initial value
53+
handleResize();
54+
55+
// Add event listener for window resize
56+
window.addEventListener('resize', handleResize);
57+
58+
// Cleanup
59+
return () => {
60+
clearInterval(interval);
61+
window.removeEventListener('resize', handleResize);
62+
};
4763
}, []);
4864

4965
const handleTouchStart = (e: React.TouchEvent) => {
@@ -57,12 +73,12 @@ export default function RecapCarousel() {
5773
const handleTouchEnd = () => {
5874
if (touchStart - touchEnd > 75) {
5975
// Swipe left
60-
setPosition((prev) => (prev >= 5 ? 1 : prev + 1));
76+
setPosition((prev) => (prev + 1) % images.length);
6177
}
6278

6379
if (touchStart - touchEnd < -75) {
6480
// Swipe right
65-
setPosition((prev) => (prev <= 1 ? 5 : prev - 1));
81+
setPosition((prev) => (prev - 1 + images.length) % images.length);
6682
}
6783
};
6884

@@ -76,18 +92,20 @@ export default function RecapCarousel() {
7692
onTouchEnd={handleTouchEnd}
7793
>
7894
{images.map((image, index) => {
79-
const offset = index + 1;
80-
const r = position - offset;
81-
const absR = Math.max(Math.abs(r), r);
82-
const zIndex = position - absR;
95+
const totalImages = images.length;
96+
const r =
97+
((position - index + totalImages / 2) % totalImages) -
98+
totalImages / 2;
99+
const absR = Math.abs(r);
100+
const zIndex = totalImages / 2 - absR;
83101

84102
return (
85103
<motion.div
86104
key={index}
87-
className="absolute aspect-video h-full w-full max-w-[90%] border-[#9EE7E5] md:rounded-[35px] md:border-4"
105+
className="absolute aspect-video h-full w-full max-w-[90%] rounded-[35px] border-4 border-[#9EE7E5]"
88106
animate={{
89107
rotateY: -20 * r,
90-
x: -250 * r,
108+
x: xOffset * r,
91109
zIndex,
92110
scale: r === 0 ? 1 : 0.8,
93111
}}

0 commit comments

Comments
 (0)