carousel prev and next button update
This commit is contained in:
@@ -26,17 +26,25 @@ const Welcome = () => {
|
|||||||
const [api, setApi] = useState<CarouselApi>();
|
const [api, setApi] = useState<CarouselApi>();
|
||||||
|
|
||||||
const scrollPrev = () => {
|
const scrollPrev = () => {
|
||||||
api?.scrollPrev();
|
if (api?.canScrollPrev()) {
|
||||||
|
api?.scrollPrev();
|
||||||
|
} else if (!api?.canScrollPrev()) {
|
||||||
|
api?.scrollTo(api?.slideNodes().length - 1);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const scrollNext = () => {
|
const scrollNext = () => {
|
||||||
api?.scrollNext();
|
if (api?.canScrollNext()) {
|
||||||
|
api?.scrollNext();
|
||||||
|
} else if (!api?.canScrollNext()) {
|
||||||
|
api?.scrollTo(0);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="custom-container">
|
<div className="custom-container">
|
||||||
<Carousel className="w-full" setApi={setApi}>
|
<Carousel className="w-full" setApi={setApi}>
|
||||||
<CarouselContent className="!pr-[8%] sm:pr-0">
|
<CarouselContent className="!pr-[15%] lg:!pr-[8%] sm:pr-0">
|
||||||
{banner.map((e, index) => (
|
{banner.map((e, index) => (
|
||||||
<CarouselItem key={index} className="relative">
|
<CarouselItem key={index} className="relative">
|
||||||
<AspectRatio ratio={16 / 8}>
|
<AspectRatio ratio={16 / 8}>
|
||||||
@@ -52,7 +60,7 @@ const Welcome = () => {
|
|||||||
</AspectRatio>
|
</AspectRatio>
|
||||||
<Button
|
<Button
|
||||||
onClick={scrollNext}
|
onClick={scrollNext}
|
||||||
className="absolute bottom-5 right-5"
|
className="absolute bottom-5 right-5 max-lg:hidden cursor-pointer"
|
||||||
variant={'secondary'}
|
variant={'secondary'}
|
||||||
size={'icon'}
|
size={'icon'}
|
||||||
>
|
>
|
||||||
@@ -60,7 +68,7 @@ const Welcome = () => {
|
|||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
onClick={scrollPrev}
|
onClick={scrollPrev}
|
||||||
className="absolute bottom-5 right-16"
|
className="absolute bottom-5 right-16 cursor-pointer max-lg:hidden"
|
||||||
variant={'secondary'}
|
variant={'secondary'}
|
||||||
size={'icon'}
|
size={'icon'}
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user