如何在Bootstrap 4轮播中堆叠多个图像

时间:2017-12-24 14:13:45

标签: jquery css twitter-bootstrap bootstrap-4 twitter-bootstrap-4

我不知道如何处理Bootstrap 4,以及如何在一张幻灯片中显示多个小图像(如缩略图),而不是让图像填充旋转木马的宽度。我已经尝试了下面的代码,但仍然无法堆叠许多图像。

<div class="container">
    <h2 class="text-center">- Carousel -</h2><br>

    <div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
        <div class="carousel-inner">
            <div class="carousel-item active">
                <img src="http://via.placeholder.com/250x250" alt="First slide">
            </div>
            <div class="carousel-item">
                <img src="http://via.placeholder.com/250x250" alt="Second slide">
            </div>
            <div class="carousel-item">
                <img src="http://via.placeholder.com/250x250" alt="Third slide">
            </div>
            <div class="carousel-item">
                <img src="http://via.placeholder.com/250x250" alt="Fourth slide">
            </div>
            <div class="carousel-item">
                <img src="http://via.placeholder.com/250x250" alt="Fifth slide">
            </div>
            <div class="carousel-item">
                <img src="http://via.placeholder.com/250x250" alt="Sixth slide">
            </div>
        </div>

        <a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev">
            <span class="carousel-control-prev-icon" aria-hidden="true"></span>
            <span class="sr-only">Previous</span>
        </a>
        <a class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next">
            <span class="carousel-control-next-icon" aria-hidden="true"></span>
            <span class="sr-only">Next</span>
        </a>
    </div>
</div>

如果您想查看示例,可以访问https://www.rhtacademy.com/并查看“精彩集锦”部分。

2 个答案:

答案 0 :(得分:1)

您也可以在轮播幻灯片中使用标准的Bootstrap Grid system类。因此,您可以使用下面示例中的标记来实现example中显示的行为 该示例在一张幻灯片中显示五个图像,一旦轮播滑动到下一个项目,它将显示下一个五个图像的块。

&#13;
&#13;
<div id="gallery" class="carousel slide" data-ride="carousel">
    <div class="carousel-inner">
        <div class="carousel-item active">
            <div class="row">
                <div class="col">
                    <img class="img-fluid" src="http://via.placeholder.com/800x450/caa8f5/ffffff?text=Image+1" alt="Image 1"/>
                </div>

                <div class="col">
                    <img class="img-fluid" src="http://via.placeholder.com/800x450/9984d4/ffffff?text=Image+2" alt="Image 2"/>
                </div>

                <div class="col">
                    <img class="img-fluid" src="http://via.placeholder.com/800x450/592e83/ffffff?text=Image+3" alt="Image 3"/>
                </div>

                <div class="col">
                    <img class="img-fluid" src="http://via.placeholder.com/800x450/230c33/ffffff?text=Image+4" alt="Image 4"/>
                </div>

                <div class="col">
                    <img class="img-fluid" src="http://via.placeholder.com/800x450/b27c66/ffffff?text=Image+5" alt="Image 5"/>
                </div>
            </div>
        </div>

        <div class="carousel-item">
            <div class="row">
                <div class="col">
                    <img class="img-fluid" src="http://via.placeholder.com/800x450/f35b04/ffffff?text=Image+6" alt="Image 6"/>
                </div>

                <div class="col">
                    <img class="img-fluid" src="http://via.placeholder.com/800x450/f18701/ffffff?text=Image+7" alt="Image 7"/>
                </div>

                <div class="col">
                    <img class="img-fluid" src="http://via.placeholder.com/800x450/f7b801/ffffff?text=Image+8" alt="Image 8"/>
                </div>

                <div class="col">
                    <img class="img-fluid" src="http://via.placeholder.com/800x450/7678ed/ffffff?text=Image+9" alt="Image 9"/>
                </div>

                <div class="col">
                    <img class="img-fluid" src="http://via.placeholder.com/800x450/3d348b/ffffff?text=Image+10" alt="Image 10"/>
                </div>
            </div>
        </div>
    </div>

    <a class="carousel-control-prev" href="#gallery" role="button" data-slide="prev">
        <span class="carousel-control-prev-icon" aria-hidden="true"></span>
        <span class="sr-only">Previous</span>
    </a>

    <a class="carousel-control-next" href="#gallery" role="button" data-slide="next">
        <span class="carousel-control-next-icon" aria-hidden="true"></span>
        <span class="sr-only">Next</span>
    </a>
</div>


<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js"></script>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

尝试在下一个按钮上触发点击事件。 像这样:

var timer = setInterval(function(){
    $('#nextButton').trigger('click');
 },2000)

单击上一个按钮时,不要忘记重置计时器。否则你可能会感到一些小故障。