Bootstrap 4 Carousel滑块不工作

时间:2018-02-16 10:18:49

标签: carousel bootstrap-4

我遇到了一些严重的问题,可以通过旋转木马进入下一张幻灯片。我可能会遗漏一些非常基本的东西,但无论我做什么,它似乎都没有起作用!我也试过使用Javascript,但无济于事。

            <div id="mycarousel" class="carousel-slide" data-ride="carousel">
            <div class="carousel-inner" role="listbox">
                <div class="carousel-item active text-center p-4">
                    <h1 class="header-h1">WE'RE READY, ARE YOU? </h1>
                    <H2 class="header-h2">COME AND JOIN US FOR A SHOOT</H2>
                    <a href="/" class="btn btn-default">FIND OUT MORE</a>
                </div>
                <div class="carousel-item text-center p-4">
                    <h1 class="header-h1">COME AND </h1>
                    <H2 class="header-h2">HAVE</H2>
                    <a href="/" class="btn btn-default">A GO</a></p>
                </div>
            </div>
            <a class="carousel-control-prev" href="#mycarousel" 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="#mycarousel" role="button" data-slide="next">
                <span class="carousel-control-next-icon" aria-hidden="true"></span>
                <span class="sr-only">Next</span>
            </a>
        </div>

1 个答案:

答案 0 :(得分:4)

使用以下工作轮播滑块模板作为起点(包括您在模板中看到的完全相同顺序的所有CDN文件),然后逐个用您自己的内容逐个替换该模板的部分内容。

一次只做一件事,一旦你添加的东西打破了整个事情,你就会立即知道罪魁祸首。

这是工作模板(点击下面的&#34;运行代码段&#34;按钮,然后展开到整页):

&#13;
&#13;
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
    <ol class="carousel-indicators">
        <li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
        <li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
        <li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
    </ol>
    <div class="carousel-inner">
        <div class="carousel-item active">
            <img class="d-block w-100" src="https://placeimg.com/1080/500/animals" alt="First slide">
            <div class="carousel-caption d-none d-md-block">
                <h5>My Caption Title (1st Image)</h5>
                <p>The whole caption will only show up if the screen is at least medium size.</p>
            </div>
        </div>
        <div class="carousel-item">
            <img class="d-block w-100" src="https://placeimg.com/1080/500/arch" alt="Second slide">
        </div>
        <div class="carousel-item">
            <img class="d-block w-100" src="https://placeimg.com/1080/500/nature" alt="Third slide">
        </div>
    </div>
    <a class="carousel-control-prev" href="#carouselExampleIndicators" 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="#carouselExampleIndicators" role="button" data-slide="next">
        <span class="carousel-control-next-icon" aria-hidden="true"></span>
        <span class="sr-only">Next</span>
    </a>
</div>
&#13;
&#13;
&#13;