【问题标题】:Bootstrap Carousel does not slideBootstrap Carousel 不滑动
【发布时间】:2015-02-19 18:25:31
【问题描述】:

我正在使用引导轮播:

<header id="carousel" class="carousel slide">
        <!-- Indicators -->
        <ol class="carousel-indicators">
            <li data-target="#carousel" data-slide-to="0" class="active"></li>
            <li data-target="#carousel" data-slide-to="1"></li>
            <li data-target="#carousel" data-slide-to="2"></li>
        </ol>

        <!-- Wrapper for slides -->
        <div class="carousel-inner">
            <div class="item active">
                <div class="fill" style="background-image:url('images/fotografie1.JPG');"></div>
                <div class="carousel-caption">
                    <h2>Caption 1</h2>
                    <p>hihihaio</p>
                </div>
            </div>
            <div class="item">
                <div class="fill" style="background-image:url('images/fotografie1.JPG');"></div>
                <div class="carousel-caption">
                    <h2>Caption 2</h2>
                </div>
            </div>
            <div class="item">
                <div class="fill" style="background-image:url('images/fotografie1.JPG');"></div>
                <div class="carousel-caption">
                    <h2>Caption 3</h2>
                </div>
            </div>
        </div>

        <!-- Controls -->
         <a class="left carousel-control" href="#carousel" role="button" data-slide="prev">
    <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
    <span class="sr-only">Previous</span>
  </a>
  <a class="right carousel-control" href="#carousel" role="button" data-slide="next">
    <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
  </a>
</div>
    </header>

图片不滑动,也无法点击上一张或下一张图片。我脑子里有正确的(更新的)版本。以下是我的想法。

<!-- Script to Activate the Carousel -->
<script>

$('.carousel').carousel({
    interval: 5000 //changes the speed
})
</script>

我寻找过有同样问题的其他人,但他们的解决方案不适用于我的。当我在 Google Chrome 中打开它并使用元素检查器时出现这些错误,它们是什么意思?

【问题讨论】:

    标签: jquery css twitter-bootstrap carousel


    【解决方案1】:

    确保在使用 JQuery Javascript(例如 Bootstrap)之前已加载 JQuery。

    你的代码没问题。

    JSFiddle

    对:(加载Jquery后引用JQuery)

    <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
    

    错误:(在加载 JQuery 之前引用 JQuery)

    <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet">
    <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    

    【讨论】:

      【解决方案2】:

      您的 HTML 似乎不包含运行 Bootstrap Javascript 和其他 jQuery 相关组件所需的 jQuery。

      在包含其他所有组件(如 Bootstrap.js)之前,您必须在正文末尾包含 jQuery(请参阅下面的示例 Bootstrap 模板)。

      <!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">
          <title>Bootstrap 101 Template</title>
      
          <!-- Bootstrap stylesheet-->
          <link href="css/bootstrap.min.css" rel="stylesheet">
        </head>
        <body>
          YOUR CAROUSEL HERE (marked with class='carousel')
      
          <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
          <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
      
          <!-- Bootstrap.js (Include all compiled plugins (below), or include individual files as needed) -->
          <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
      
          <!-- Script to Activate the Carousel -->
          <script>  
              $('.carousel').carousel({
                  interval: 5000 //changes the speed
              });
          </script>
        </body>
      </html>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-01-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-12-15
        • 2020-08-19
        相关资源
        最近更新 更多