Bootstrap 5仅在单击下一个和上一个按钮时使两个轮播同时滑动

Posted

技术标签:

【中文标题】Bootstrap 5仅在单击下一个和上一个按钮时使两个轮播同时滑动【英文标题】:Bootstrap 5 make two carousels slide at the same time when clicking the next and previous buttons only 【发布时间】:2022-01-09 06:22:22 【问题描述】:

我正在使用引导 5 轮播。我需要两个旋转木马同时滑动。我使用了data-bs-target=".carousel",但它不起作用。我的代码如下:

<div class="section-04">
    <div class="container-fluid">
        <div class="row col-reverse">
            <div class="col-md-6 p-left">
            
                <div class="left-block">
                    <div class="row b-top">
                        <div class="col-md-6">
                            <h3>
                                The <br>
                                Most <br>
                                Wanted
                            </h3>
                        </div>
                        <div class="col-md-6">
                            <p>
                                Current favorites, new icons and the best sellers from this month.
                            </p>
                            <a href="#" class="btn btn-main move-btn">Explore More</a>
                        </div>
                    </div>
                    <div id="carouselExampleControls2" class="carousel slide carousel-sync" data-bs-interval="false" data-bs-ride="carousel">
                        <div class="carousel-inner">
                            <div class="carousel-item active">
                                <div class="carousel-card">
                                    <div class="row">
                                        <div class="col-md-12">
                                            <h3 class="section-text">
                                                Petite Collection
                                            </h3>
                                            <hr class="mb-3">
                                        </div>
                                        <div class="col-md-6">
                                            <h2>
                                                Spoiled <br>
                                                Lashes
                                            </h2>
                                        </div>
                                        <div class="col-md-6">
                                            <p class="card-price">
                                                $16.00 <span>USD</span>
                                            </p>
                                            <a href="#" class="btn btn-main">Add to bag</a> <a href="#" class="btn btn-main btn-fav ms-2"><i class="bi bi-heart"></i></a>
                                        </div>
                                        <div class="col-md-12">
                                            <hr class="mt-3">
                                            <div class="card-reviews mb-4">
                                                #reviews
                                            </div> 
                                            <div class="description">
                                                <p>
                                                    Everyday lashes made of synthetic silk material with gradient flare. The added volume on the outer corners elongates your eyes for a simple false lashes look. Choose Mini Me subtle false lashes for easy no trim, no measure application. Comes on a ¾ cotton band.
                                                </p>
                                            </div>
                                            <hr class="mt-3">
                                            <a href="#" class="btn-link">Learn more</a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="carousel-item">
                                <div class="carousel-card">
                                    <div class="row">
                                        <div class="col-md-12">
                                            <h3 class="section-text">
                                                Petite Collection
                                            </h3>
                                            <hr class="mb-3">
                                        </div>
                                        <div class="col-md-6">
                                            <h2>
                                                Spoiled <br>
                                                Lashes
                                            </h2>
                                        </div>
                                        <div class="col-md-6">
                                            <p class="card-price">
                                                $16.00 <span>USD</span>
                                            </p>
                                            <a href="#" class="btn btn-main">Add to bag</a> <a href="#" class="btn btn-main btn-fav ms-2"><i class="bi bi-heart"></i></a>
                                        </div>
                                        <div class="col-md-12">
                                            <hr class="mt-3">
                                            <div class="card-reviews mb-4">
                                                #reviews
                                            </div> 
                                            <div class="description">
                                                <p>
                                                    Everyday lashes made of synthetic silk material with gradient flare. The added volume on the outer corners elongates your eyes for a simple false lashes look. Choose Mini Me subtle false lashes for easy no trim, no measure application. Comes on a ¾ cotton band.
                                                </p>
                                            </div>
                                            <hr class="mt-3">
                                            <a href="#" class="btn-link">Learn more</a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="carousel-item">
                                <div class="carousel-card">
                                    <div class="row">
                                        <div class="col-md-12">
                                            <h3 class="section-text">
                                                Petite Collection
                                            </h3>
                                            <hr class="mb-3">
                                        </div>
                                        <div class="col-md-6">
                                            <h2>
                                                Spoiled <br>
                                                Lashes
                                            </h2>
                                        </div>
                                        <div class="col-md-6">
                                            <p class="card-price">
                                                $16.00 <span>USD</span>
                                            </p>
                                            <a href="#" class="btn btn-main">Add to bag</a> <a href="#" class="btn btn-main btn-fav ms-2"><i class="bi bi-heart"></i></a>
                                        </div>
                                        <div class="col-md-12">
                                            <hr class="mt-3">
                                            <div class="card-reviews mb-4">
                                                #reviews
                                            </div> 
                                            <div class="description">
                                                <p>
                                                    Everyday lashes made of synthetic silk material with gradient flare. The added volume on the outer corners elongates your eyes for a simple false lashes look. Choose Mini Me subtle false lashes for easy no trim, no measure application. Comes on a ¾ cotton band.
                                                </p>
                                            </div>
                                            <hr class="mt-3">
                                            <a href="#" class="btn-link">Learn more</a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            
            </div>
            <div class="col-md-6 p-right p-0 ">
                <div class="right-block">
                    
                    <div id="carouselExampleControls" class="carousel slide carousel-sync" data-bs-interval="false" data-bs-ride="carousel">
                        <div class="carousel-inner">
                            <div class="carousel-item active">
                                <div class="carousel-img-container jalign">
                                    <img src="https://cdn.shopify.com/s/files/1/0612/9139/7358/files/img-30.png?v=1638393794" >
                                </div>
                            </div>
                            <div class="carousel-item">
                                <div class="carousel-img-container jalign">
                                    <img src="https://cdn.shopify.com/s/files/1/0612/9139/7358/files/img-30.png?v=1638393794" >
                                </div>
                            </div>
                            <div class="carousel-item">
                                <div class="carousel-img-container jalign">
                                    <img src="https://cdn.shopify.com/s/files/1/0612/9139/7358/files/img-30.png?v=1638393794" >
                                </div>
                            </div>
                        </div>
                        <button class="carousel-control-prev" type="button" data-bs-target=".carousel" data-bs-slide="prev">
                            <span class="carousel-control-prev-icon" aria-hidden="true"></span>
                            <span class="visually-hidden">Previous</span>
                        </button>
                        <button class="carousel-control-next" type="button" data-bs-target=".carousel" data-bs-slide="next">
                            <span class="carousel-control-next-icon" aria-hidden="true"></span>
                            <span class="visually-hidden">Next</span>
                        </button>
                    </div>

                </div>
            </div>
        </div>
    </div>

【问题讨论】:

选项 2 解决了我的问题,***.com/questions/20710222/… 【参考方案1】:

全部删除并重新开始。你的轮播肯定会更容易。您的代码中没有任何内容能让您的生活变得轻松。 Columns inside Columns inside Rows 也是 Columns 并且都带有各种附加类......让我们重新开始......

<section>
 <div class="container">
   <div clss="row">

     <!-- Carousel from GetBootstrap.com Version 5 -->

   </div>
 </div>
</section>

【讨论】:

感谢您的评论。我试过了,但不幸的是,它没有回答我的问题。

以上是关于Bootstrap 5仅在单击下一个和上一个按钮时使两个轮播同时滑动的主要内容,如果未能解决你的问题,请参考以下文章

将下一个和上一个按钮添加到 ListView

如何在 C# 中使用 Linq to JSON 在单击按钮时检索下一个和上一个 id

在模态中的wordpress帖子中添加下一个和上一个按钮

单击卡片以在带有下一个和上一个按钮的弹出窗口上显示其各自的详细信息

如何在Java中单击下一个和上一个按钮时显示下一个和上一个记录?

Bootstrap 导航栏切换器仅在第一次单击时起作用