简体   繁体   中英

I can't seem to get Bootstrap Carousel to work locally, but it works on codepen

I'm trying to get a bootstrap carousel working on my site, and it shows collapsed, but instead of going to the next slide, it just "jumps" down a little bit.

Here is my header which might be out of order:

<head>
<script src="https://code.jquery.com/jquery-3.1.0.min.js" type="javascript"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" type="javascript"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/2.0.0-beta.17/angular2-all-testing.umd.dev.js" type="javascript"></script>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet">
<link href="css/main.css" rel="stylesheet">

And here is the HTML for the carousel that I'm having trouble with:

  <div class="carousel slide" id="spinner" data-ride="carousel">
  <ol class="carousel-indicators">
    <li class="active" data-target="#spinner" data-slide-to="0"></li>
    <li data-target="#spinner" data-slide-to="1"></li>
    <li data-target="#spinner" data-slide-to="2"></li>
  </ol>
  <div class="carousel-inner" role="listbox">
    <div class="item active"><img src="http://placehold.it/600x300"></div>
    <div class="item"><img src="http://placehold.it/600x300"></div>
    <div class="item"><img src="http://placehold.it/600x300"></div>
  </div>
  <a class="left carousel-control" href="#spinner" role="button" data-slide="prev">
  <span class="icon-prev" aria-hidden="true">
  </span><span class="sr-only">Previous</span>
  </a>
  <a class="right carousel-control" href="#spinner" role="button" data-slide="next">
  <span class="icon-next" aria-hidden="true">
  <span class="sr-only">Next</span></span></a>
    </div>

As a note, I've gotten this to work on Codepen, but it doesn't run on the machine I'm coding on.

Carousel on Codepen

I'm not concerned with the look of the Carousel on codepen, just the functionality.

jQuery 3 has some compatibility issues with bootstrap 3. Your codepen is using jquery 2.2.4. Switch your jQuery version to 2.2.4

It works with previous version of jQuery, not the version 3.x.

The snippet:

 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://code.jquery.com/jquery-2.2.4.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <div class="carousel slide" id="spinner" data-ride="carousel"> <ol class="carousel-indicators"> <li class="active" data-target="#spinner" data-slide-to="0"></li> <li data-target="#spinner" data-slide-to="1"></li> <li data-target="#spinner" data-slide-to="2"></li> </ol> <div class="carousel-inner" role="listbox"> <div class="item active"><img src="http://placehold.it/600x300"></div> <div class="item"><img src="http://placehold.it/600x300"></div> <div class="item"><img src="http://placehold.it/600x300"></div> </div> <a class="left carousel-control" href="#spinner" role="button" data-slide="prev"> <span class="icon-prev" aria-hidden="true"> </span><span class="sr-only">Previous</span> </a> <a class="right carousel-control" href="#spinner" role="button" data-slide="next"> <span class="icon-next" aria-hidden="true"> <span class="sr-only">Next</span></span></a> </div> 

Use this link in your head tag

<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM