微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Bootstrap Carousel Image 滑块,我怎样才能让它工作?

如何解决Bootstrap Carousel Image 滑块,我怎样才能让它工作?

我需要这方面的帮助。这是我第一次使用引导程序,我已经厌倦了。我想制作 3 张滑动并每次点击更改的图像。我在 Boostrap 网站上找到了这段代码,但它不起作用。我正在使用他们的链接和脚本。

请帮帮我。对不起我的英语

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
    integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js" integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.min.js" integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF" crossorigin="anonymous"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

<div id = "slides" class = "carousel slide" data-ride = "carousel">
        <ul class = "carousel-indicators">
            <li data-target="#slides" data-slide-to="0" class ="active"></li>
            <li data-target="#slides" data-slide-to="1"></li>
            <li data-target="#slides" data-slide-to="2"></li>
        </ul>
        <div class = "carousel-inner">
            <div class = "carousel-item active">
                <img src = "img/img1.jpg">
                <div class = "carousel-caption">
                    <h1 class = "display-2">Test</h1>
                    <h3>Testing of the test</h3>
                    <button type = "button" class = "btn btn-outline-light btn-lg">tester</button>
                    <button type = "button" class = "btn btn-primary btn-lg">Jop</button>
                </div>
            </div>
            <div class = "carousel-item">
                <img src = "img/img2.jpg">
            </div>
            <div class = "carousel-item">
                <img src = "img/img3.jpg">
            </div>
        </div>
    </div>

解决方法

您还没有添加下一个和预览按钮,请尝试使用此代码:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width,initial-scale=1.0" />
    <title>Document</title>
    <link
    href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css"
    rel="stylesheet"
    integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
    crossorigin="anonymous"
    />
  </head>
  <body>

    <div id = "slides" class = "carousel slide" data-ride = "carousel" style="height: 100;">

      <div class = "carousel-inner">
          <div class = "carousel-item active">
            <img src = "https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885__480.jpg" class="d-block w-100">
            <div class = "carousel-caption">
                  <h1 class = "display-2">Test</h1>
                  <h3>Testing of the test</h3>
                  <button type = "button" class = "btn btn-outline-light btn-lg">tester</button>
                  <button type = "button" class = "btn btn-primary btn-lg">Jop</button>
              </div>
          </div>
          <div class = "carousel-item">
              <img src = "https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885__480.jpg" class="d-block w-100">
          </div>
          <div class = "carousel-item">
              <img src = "https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885__480.jpg" class="d-block w-100">
          </div>
        </div>
        <button class="carousel-control-prev" type="button" data-bs-target="#slides" 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="#slides" data-bs-slide="next">
          <span class="carousel-control-next-icon" aria-hidden="true"></span>
          <span class="visually-hidden">Next</span>
        </button>
  </div>

    <script
      src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js"
      integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p"
      crossorigin="anonymous"
    ></script>
    <script
      src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.min.js"
      integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF"
      crossorigin="anonymous"
    ></script>
  </body>
</html>

,

您以错误的顺序添加了 JS 文件(jquery 必须在 bootstrap 文件之前!)并且您使用了 Bootstrap 4 语法但调用了版本 5 资源

<html>
  <head>
    <title></title>
    <meta content="">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
    integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    <style>
        #slides{ margin: 0 auto;}
        #slides,.carousel-inner,.carousel-item{
            height: 400px; width: 600px;
        }

    </style>
  </head>
  <body>

    <div id="slides" class="carousel slide" data-ride="carousel">
        <ul class="carousel-indicators">
            <li data-bs-target="#slides" data-bs-slide-to="0" class="active"></li>
            <li data-bs-target="#slides" data-bs-slide-to="1"></li>
            <li data-bs-target="#slides" data-bs-slide-to="2"></li>
        </ul>
        <div class="carousel-inner">
            <div class="carousel-item active">
                <img src="https://cdn.pixabay.com/photo/2020/02/11/16/25/manarola-4840080_960_720.jpg" class="d-block w-100">
                <div class="carousel-caption">
                    <h1 class="display-2">Test</h1>
                    <h3>Testing of the test</h3>
                    <button type="button" class="btn btn-outline-light btn-lg">tester</button>
                    <button type="button" class="btn btn-primary btn-lg">Jop</button>
                </div>
            </div>
            <div class="carousel-item">
                <img src="https://cdn.pixabay.com/photo/2020/03/24/20/40/manarola-4965450_960_720.jpg" class="d-block w-100">
            </div>
            <div class="carousel-item">
                <img src="https://cdn.pixabay.com/photo/2016/02/19/11/18/manarola-1209627_960_720.jpg" class="d-block w-100">
            </div>
        </div>

        <button class="carousel-control-prev" type="button" data-bs-target="#slides" 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="#slides" data-bs-slide="next">
            <span class="carousel-control-next-icon" aria-hidden="true"></span>
            <span class="visually-hidden">Next</span>
        </button>
    </div>
    
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

    <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js" integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.min.js" integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF" crossorigin="anonymous"></script>
  </body>
</html>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。