轮播引导程序无效

时间:2016-03-04 18:34:08

标签: twitter-bootstrap carousel

有人可以帮助我吗?我测试了自举旋转木马,但它没有用。具体来说:previuos / next按钮不起作用,旋转木马不会滑动到下一张幻灯片。这是我的页面代码,但我不知道自己做错了什么。

<!DOCTYPE html>
<html>
<head>

<title>Title</title>

<!-- META -->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- META -->

<!-- CSS -->
<link href="css/stile.css" rel="stylesheet" type="text/css">
<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
<!-- CSS -->  

</head>
<body>

<div class="container">

    <div id="myCarousel" class="carousel slide">

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

        <div class="carousel-inner">
            <div class="item active">
                <img src="image1.jpg" alt="image1.jpg">
            </div>
            <div class="item">
                <img src="image2.jpg" alt="image2.jpg">
            </div>
            <div class="item">
                <img src="image3.jpg" alt="image3.jpg">
            </div>
        </div>

        <a class="left carousel-control" href="#myCarousel" data-slide="prev">
            <span class="icon-prev"></span>
        </a>
        <a class="right carousel-control" href="#myCarousel" data-slide="next">
            <span class="icon-next"></span>
        </a>
    </div>
</div>

<!-- JS -->
<script src="//code.jquery.com/jquery-latest.js"></script>
<script src="js/bootstrap.min.js"></script>
<!-- JS -->
</body>
</html>

2 个答案:

答案 0 :(得分:3)

您是否使用以下JS调用了Carousel?

    $('.carousel').carousel({
  interval: 2000
})

尝试将链接/脚本放在顶部:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

这些是嵌入式链接,而不是您的根文件。你可以使用你的,但把它们放在顶部,看看是否有帮助。

答案 1 :(得分:0)

不确定您的第一个样式表条目是否正确。它应该是stile.css吗?

您应该包含以下样式表(确保它位于样式表文件夹中)

<link href="css/carousel.css" rel="stylesheet">

我在我的一个网站中使用轮播滑块。您的代码似乎缺少一些细节。第一个div应附加data-ride =&#34; carousel&#34;&gt; 我的第二个div包括role =&#34; listbox&#34;&gt;而且你没有。我已将我的代码包含在您的信息中。我希望这会有所帮助。

<!-- Carousel
================================================== -->
<div id="myCarousel" class="carousel slide" data-ride="carousel">
  <!-- Indicators -->
  <ol class="carousel-indicators">
    <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
    <li data-target="#myCarousel" data-slide-to="1"></li>
    <li data-target="#myCarousel" data-slide-to="2"></li>
  </ol>
  <div class="carousel-inner" role="listbox">
    <div class="item active">
      <img class="first-slide" src="images/Dock1.jpg" alt="First slide">
      <div class="container">
        <div class="carousel-caption">
          <h1>If you have a web site it needs to be responsive and &quot;mobile
            friendly&quot; </h1>
          <p> </p>
          <p><a class="btn btn-lg btn-primary" href="https://donfiler.us" role="button">Sign up today</a></p>
        </div>
      </div>
    </div>
    <div class="item">
      <img class="second-slide" src="images/Forest1.jpg" alt="Second slide">
      <div class="container">
        <div class="carousel-caption">
          <h1> Revamp your website usability with HTML to WordPress Conversion Services </h1>
          <p></p>
          <p><a class="btn btn-lg btn-primary" href="https://donfiler.us" role="button">Learn more</a></p>
        </div>
      </div>
    </div>
    <div class="item">
      <img class="third-slide" src="images/Tree1.jpg" alt="Third slide">
      <div class="container">
        <div class="carousel-caption">
          <h1>Contact Us Today to Get Started on Your New Site </h1>
          <p> </p>
          <p><a class="btn btn-lg btn-primary" href="https://donfiler.us/portfolio.html" role="button">Browse gallery</a></p>
        </div>
      </div>
    </div>
  </div>
  <a class="left carousel-control" href="#myCarousel" 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="#myCarousel" role="button" data-slide="next">
    <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
  </a>
</div><!-- /.carousel -->