最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Bootstrap Carousel not Working (showing all images at once) - Stack Overflow

programmeradmin3浏览0评论

I'm trying to add a carousel to my Bootstrap 3 website. The code used is directly from . The code is also quite undocumented, so I had to make some guesses. The carousel just displays all three images stacked on top of one another. I am fairly certain that my javascript and jQuery are working, because I have a navbar set up that has working dropdowns.

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

  <!-- Wrapper for slides -->
  <div class="carousel-inner">
    <div class="item active">
    <img src="" alt=“Slide 1”>
      <div class="carousel-caption">
        <h1>Slide 1</h1>
        <p>Slide 1 Description</p>
      </div>
    </div>
  </div>
  <div class="carousel-inner">
    <div class="item active">
      <img src="" alt=”Slide 2”>
      <div class="carousel-caption">
        <h1>Slide 2</h1>
        <p>Slide to Description</p>
      </div>
    </div>
  </div>
  <div class="carousel-inner">
    <div class="item active">
    <img src="" alt=“Slide “3>
      <div class="carousel-caption">
        <h1>Slide 3</h1>
        <p>Slide 3 Description</p>
      </div>
    </div>
  </div>

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

EDIT: I did some more work on it (thanks answering guys) and I think I got it. The slides actually animate and, unlike a few of my attempts, it loops back to the start. Hopefully this is it.

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

    <!-- Wrapper for slides -->
        <div class="carousel-inner">
            <!-- Slide 1-->
            <div class="item active">
                <img src="" alt="Slide 1" />
                <div class="carousel-caption">
                    <h1>Slide 1</h1>
                    <p>Slide 1 Description</p>
                </div>
            </div>

            <!-- Slide 2-->
              <div class="item">
                  <img src="" alt="Slide 2" />
                  <div class="carousel-caption">
                      <h1>Slide 2</h1>
                      <p>Slide 2 Description</p>
                  </div>
              </div>

          <!-- Slide 3-->
            <div class="item">
                <img src="" alt="Slide 3" />
                <div class="carousel-caption">
                    <h1>Slide 3</h1>
                    <p>Slide 3 Description</p>
                </div>
            </div>
          </div>


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

I'm trying to add a carousel to my Bootstrap 3 website. The code used is directly from http://getbootstrap.com/javascript/#carousel. The code is also quite undocumented, so I had to make some guesses. The carousel just displays all three images stacked on top of one another. I am fairly certain that my javascript and jQuery are working, because I have a navbar set up that has working dropdowns.

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

  <!-- Wrapper for slides -->
  <div class="carousel-inner">
    <div class="item active">
    <img src="http://placehold.it/1200x480" alt=“Slide 1”>
      <div class="carousel-caption">
        <h1>Slide 1</h1>
        <p>Slide 1 Description</p>
      </div>
    </div>
  </div>
  <div class="carousel-inner">
    <div class="item active">
      <img src="http://placehold.it/1200x480" alt=”Slide 2”>
      <div class="carousel-caption">
        <h1>Slide 2</h1>
        <p>Slide to Description</p>
      </div>
    </div>
  </div>
  <div class="carousel-inner">
    <div class="item active">
    <img src="http://placehold.it/1200x480" alt=“Slide “3>
      <div class="carousel-caption">
        <h1>Slide 3</h1>
        <p>Slide 3 Description</p>
      </div>
    </div>
  </div>

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

EDIT: I did some more work on it (thanks answering guys) and I think I got it. The slides actually animate and, unlike a few of my attempts, it loops back to the start. Hopefully this is it.

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

    <!-- Wrapper for slides -->
        <div class="carousel-inner">
            <!-- Slide 1-->
            <div class="item active">
                <img src="http://placehold.it/1200x480" alt="Slide 1" />
                <div class="carousel-caption">
                    <h1>Slide 1</h1>
                    <p>Slide 1 Description</p>
                </div>
            </div>

            <!-- Slide 2-->
              <div class="item">
                  <img src="http://placehold.it/1200x480" alt="Slide 2" />
                  <div class="carousel-caption">
                      <h1>Slide 2</h1>
                      <p>Slide 2 Description</p>
                  </div>
              </div>

          <!-- Slide 3-->
            <div class="item">
                <img src="http://placehold.it/1200x480" alt="Slide 3" />
                <div class="carousel-caption">
                    <h1>Slide 3</h1>
                    <p>Slide 3 Description</p>
                </div>
            </div>
          </div>


  <!-- Controls -->
  <a class="left carousel-control" href="#carousel-example-generic" data-slide="prev">
    <span class="icon-prev"></span>
  </a>
  <a class="right carousel-control" href="#carousel-example-generic" data-slide="next">
    <span class="icon-next"></span>
  </a>
</div>
Share Improve this question edited Oct 24, 2013 at 19:39 asked Oct 23, 2013 at 22:26 user2333842user2333842
Add a comment  | 

4 Answers 4

Reset to default 8

As already told all your carousel items has been marked active and these items are wrapped in different carousel-inner class. You need to wrap only items in carousel-inner class and not link containing carousel-control class. In order to carousel slide automatically you need to include:

$(function(){
  $('#carousel-example-generic').carousel();
});

Check this link:Updated code

All of your slides are marked as active... Only one should have active class at any one time.

You also have too many carousel-inner divs. All slides need wrapping in one carousel-inner.

<div class="item active">

remove active class from all div excluding first one

I faced the same issue today. I downloaded bootstrap.min.css from http://getbootstrap.com and was using that css. That css was showing the issue. I changed the css source to https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css and it solved the problem.

发布评论

评论列表(0)

  1. 暂无评论