bootstrap carousel not working images

834 views Asked by At

I am trying to make a carousel using bootstrap following is my code, but problem is it shows only one image. I have added total three images but it only shows one of them. and I am also not able to click on icons for buttons. I have added buttons for previous and next but they are also not seen in the page.

<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="1.jpg" alt="Fun" class="img-responsive">
        </div>
        <div class="item">
            <img src="2.jpg" alt="play" class="img-responsive">
        </div>
        <div class="item">
            <img src="3.jpg" alt="learn" class="img-responsive">
        </div>
    </div>
    <a class="carousel-control-left" href="mycarousel" data-slide="prev">
        <span class="icon-prev"></span>
    </a>
    <a class="carousel-control-right" href="mycarousel" data-slide="next">
        <span class="icon-next"></span>
    </a>    
</div>

I have added both js and jquery.

2

There are 2 answers

0
Thomas Mol On

remove hyphen at first div:

class="carousel slide"

It also seems that you are missing the controls. That's why you can't go to the next slide. Here is the full code of a carousel provided by the bootstrap documentation linked here.

  <!-- Wrapper for slides -->
  <div class="carousel-inner" role="listbox">
    <div class="item active">
      <img src="..." alt="...">
      <div class="carousel-caption">
        ...
      </div>
    </div>
    <div class="item">
      <img src="..." alt="...">
      <div class="carousel-caption">
        ...
      </div>
    </div>
    ...
  </div>

  <!-- Controls -->
  <a class="left carousel-control" href="#carousel-example-generic" 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-example-generic" role="button" data-slide="next">
    <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
  </a>
</div>
0
Prajwal K M On

Javascript

Include this in script:

<script language="JavaScript" type="text/javascript">
  $(document).ready(function(){
    $('.carousel').carousel({
      interval: 2000
    })
  });    
</script>

So that your code should be like this:

<!-- jquery should be called first -->
<script language="JavaScript" type="text/javascript" src="scripts/jquery.js"></script>
<!-- javascript -->
<script language="JavaScript" type="text/javascript" src="scripts/bootstrap.min.js"></script>
  <!-- Carousel -->
<script language="JavaScript" type="text/javascript">
  $(document).ready(function(){
    $('.carousel').carousel({
      interval: 3000
    })
  });    
</script>