Carousel bootstrap doesn't work

核能气质少年 提交于 2019-12-13 13:40:39

问题


Someone can help me?I'm testing the bootstrap carousel but it doesn't work. Specifically: the previuos/next buttons don't work and the carousel doesn't slide to the next slide. this is my page's code but I don't know what I'm doing wrong.

<!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>

回答1:


Have you called the Carousel with the below JS?

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

Try putting the link/script at the top:

<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>

These are embeded links and not from your root file. you can use yours but place them at the top and see if that helps.




回答2:


Not sure if your first stylesheet entry is correct. Is it supposed to be stile.css?

You should include the following stylesheet (making sure it is in your stylesheet folder)

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

I use the carousel slider in one of my sites. Your code seems to be missing a few details. The first div should be appended with data-ride="carousel"> My second div includes role="listbox"> and your doesn't. I have included my code for your information. I hope this helps.

<!-- 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 -->


来源:https://stackoverflow.com/questions/35803549/carousel-bootstrap-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!