How to change the interval time on bootstrap carousel?

前端 未结 5 2216
情书的邮戳
情书的邮戳 2020-12-09 08:08

I have a bootstrap carousel on my web page, I\'m trying the increase the time interval between each slide. The default delay of 5000 milliseconds is too fast, I need about 1

相关标签:
5条回答
  • 2020-12-09 08:23

    You can also use the data-interval attribute eg. <div class="carousel" data-interval="10000">

    0 讨论(0)
  • 2020-12-09 08:31
            You need to set interval in  main div as data-interval tag .
            so it is working fine and you can give different time to different slides.
    
           <!--main div -->
          <div data-ride="carousel" class="carousel slide" data-interval="100" id="carousel-example-generic">
      <!-- Indicators -->
      <ol class="carousel-indicators">
                                    <li data-target="#carousel-example-generic" data-slide-to="0" class=""></li>
                                 i>
                                                </ol>
    
      <!-- Wrapper for slides -->
      <div role="listbox" class="carousel-inner">
           <div class="item">
              <a class="carousel-image" href="#">
               <img alt="image" src="image.jpg">
              </a>
            </div>
        </div>
     </div>
    
    0 讨论(0)
  • 2020-12-09 08:34

    You can simply use the data-interval attribute of the carousel class.

    It's default value is set to data-interval="3000" i.e 3seconds.

    All you need to do is set it to your desired requirements.

    0 讨论(0)
  • 2020-12-09 08:39

    The best way to get rid on it is adding or modifying the data-interval attribute like this:

    <div data-ride="carousel" class="carousel slide" data-interval="10000" id="myCarousel">
    

    It's specified on ms like it's usually on js, so 1000 = 1s, 3000 = 3s... 10000 = 10s.

    By the way you can also specify it at 0 for not sliding automatically. It's useful when showing product images on mobile for example.

    <div data-ride="carousel" class="carousel slide" data-interval="0" id="myCarousel">
    
    0 讨论(0)
  • 2020-12-09 08:41

    You can use the options when initializing the carousel, like this:

    // interval is in milliseconds. 1000 = 1 second -> so 1000 * 10 = 10 seconds
    $('.carousel').carousel({
      interval: 1000 * 10
    });
    

    or you can use the interval attribute directly on the HTML tag, like this:

    <div class="carousel" data-interval="10000">
    

    The advantage of the latter approach is that you do not have to write any JS for it - while the advantage of the former is that you can compute the interval and initialize it with a variable value at run time.

    0 讨论(0)
提交回复
热议问题