@@ -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