简体   繁体   中英

Bootstrap 3 Carousel Caption Delay

Website: http://freedomcreativesolutions.com/old/steamsource/

Problem: Trying to implement the javascript slide.bs.carousel into the code so that the caption delays and comes in a few seconds after the picture loads in the slideshow. I placed the code for 'slide.bs.carousel' in a script tag before the closing body tag rather than in a separate js file. But it seems like its not working at all and still comes in along with the picture.

What I did: http://jsfiddle.net/fuhs3smx/

Seems like its not working in Jsfiddle (new to this program) which is why I gave the link to the website so you'd guys atleast get an idea of what I'm trying to accomplish.

Guess what I'm trying to ask here is, where exactly should I place the script for 'slide.bs.carousel'? Everything looks good to me and my guess is that I'm placing the script in the wrong area.

<div id="carousel-example-generic" class="carousel slide carousel-fade" data-ride="carousel">
  <!-- 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" role="listbox">
    <div class="item active">
      <img src="./img/family-new.jpg" alt="We are Serious about Clean!">
      <div class="carousel-caption">
       <h3>Safe for the whole family!</h3>
      </div>
    </div>
    <div class="item">
      <img src="./img/RugCleaningFacility.jpg" alt="Rug Cleaning">
      <div class="carousel-caption">
       <h3>State of the art rug cleaning facility!</h3>
      </div>
    </div>
    <div class="item">
      <img src="./img/ProfessionalWW.jpg" alt="Window Washing and Pressure Washing">
      <div class="carousel-caption">
      <h3>Professional Window Washing and Pressure Washing!</h3>
      </div>
    </div>
    <div class="item">
      <img src="./img/UpholsteryClean.jpg" alt="Upholstery Cleaning">
      <div class="carousel-caption">
       <h3>The deepest upholstery cleaning available!</h3>
      </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>

UPDATE: After including bootstrap.min.js, I'm getting this message when pulling up the dev tools:

Uncaught TypeError: undefined is not a function

carouselContainer.carousel({
    interval: slideInterval,
    cycle: true,
    pause: "hover"
}).on('slid.bs.carousel', function() {
    toggleCaption();
});

What does that mean? Maybe I've mispelled something or maybe the placement is all wrong.

Your fiddle doesn't include Bootstrap.js. You must also include jQuery as Bootstrap.js requires jQuery.

The Uncaught TypeError: jQuery.easing[this.easing] is not a function issue can be resolved by adding jQuery UI.

You'll noticed that I also placed your JS inside .ready() so that it's guaranteed to be executed after the DOM is ready.

I've updated the fiddle for you to review. http://jsfiddle.net/yongchuc/fuhs3smx/2/

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