简体   繁体   English

如何使用引导轮播显示多个项目

[英]How do I show multiple items using bootstrap carousel

I am trying to use carousel in my react project to show reviews.我正在尝试在我的反应项目中使用轮播来显示评论。 I am using bootstrap carousel.我正在使用引导轮播。 This is the carousel I am using这是我正在使用的轮播

But I want to use like this但我想这样使用

Every click on the button will slide in a item and one item will slide out.每次点击按钮都会滑入一个项目,一个项目会滑出。 I can do one at a time but not like this.我可以一次做一个,但不是这样。

Here is my Code:这是我的代码:

const ShowReviews = () => {
const { data: reviews, isLoading, refetch } = useQuery('reviews', () => fetch('https://.herokuapp.com/reviews',)
    .then(res => res.json()))
refetch()
if (isLoading) {
    return <Loading></Loading>
}
return (
    <div>
        <h1 className='text-center fw-bold my-5'>User Reviews ({reviews.length})</h1>
        <div className='bg-dark bg-opacity-25 container-fluid'>
            <Carousel>
                {reviews.map(review => <Carousel.Item> <ReviewCard
                    key={review._id}
                    review={review}
                ></ReviewCard></Carousel.Item>)}
            </Carousel>
        </div>
    </div>
);

}; };

export default ShowReviews;导出默认 ShowReviews;

Just put three review cards per Carousel.Item instead of one.只需为每个 Carousel.Item 放置三张评论卡,而不是一张。 Carousel.Item is just a wrapper for one carousel "page". Carousel.Item 只是一个轮播“页面”的包装器。

Carousel.Item is already styled in a certain way, that's why you need a container/wrapper right below it. Carousel.Item已经以某种方式设置了样式,这就是为什么您需要在其下方有一个容器/包装器。 In my example I used Stack with direction="horizontal":在我的示例中,我使用Stack with direction="horizo​​ntal":

<Carousel.Item style={{ height: 500 }}>
  <Stack
    direction="horizontal"
    className="h-100 justify-content-center align-items-center"
    gap={3}
  >
    <Card>...</Card>
    <Card>...</Card>
    <Card>...</Card>
  </Stack>
</Carousel.Item>

https://codesandbox.io/s/relaxed-poitras-4w774i https://codesandbox.io/s/relaxed-poitras-4w774i

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM