Skip to content

Commit

Permalink
Fix carousel
Browse files Browse the repository at this point in the history
  • Loading branch information
Bluesmile82 committed Oct 14, 2024
1 parent 83e588b commit 2546bd9
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions src/components/vertical-carousel/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

'use client';

import { motion, AnimatePresence, stagger } from 'framer-motion';
import { motion, AnimatePresence } from 'framer-motion';
import { useEffect, useState, Children } from 'react';

const VerticalCarousel = ({ children, className }:
Expand Down Expand Up @@ -30,27 +29,30 @@ const VerticalCarousel = ({ children, className }:

useEffect(() => {
const interval = setInterval(() => {
const nextIndex = (index + 1) % content.length;
setIndex(nextIndex);
setIndex((prevIndex) => (prevIndex + 1) % content.length);
}, 3000);
return () => clearInterval(interval);
}, [content.length, index]);
}, [content.length]);

return (
<div className={className}>
<motion.div className="relative h-[3rem] overflow-hidden">
<AnimatePresence>
<motion.div key={index} className="absolute w-full"
variants={contentAnimation}
initial="initial"
animate="animate"
exit="exit">
{content[index]}
</motion.div>
<div className="relative h-[3rem] overflow-hidden">
<AnimatePresence initial={false}>
{content.map((child, i) => (
i === index && (
<motion.div key={i} className="absolute w-full"
variants={contentAnimation}
initial="initial"
animate="animate"
exit="exit">
{child}
</motion.div>
)
))}
</AnimatePresence>
</motion.div>
</div>
</div>
);
}

export default VerticalCarousel;
export default VerticalCarousel;

0 comments on commit 2546bd9

Please sign in to comment.