49

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 10 seconds.

3
  • 2
    5000 milliseconds = 5 seconds, so use 10000 milliseconds.
    – j08691
    Aug 5, 2014 at 20:08
  • 4
    Did you read the api: getbootstrap.com/javascript/#carousel-usage The directions to set the interval are right there in the text. Either a data attribute or the config. Aug 5, 2014 at 20:09
  • Carousel.VERSION = '3.2.0' Carousel.DEFAULTS = { interval: 10000, pause: 'hover', wrap: true }
    – Alan
    Aug 5, 2014 at 20:14

7 Answers 7

131

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

4
  • 3
    This is actually a better way to do it since bootstrap has a function to interpret this by default. The JavaScript solution is more applicable in case other parameters are specifies using JavaScript.
    – Khaled
    May 1, 2015 at 13:25
  • 1
    The best solution... above all if someone works with templates and can't put this code AFTER bootstrap loading!!! Jun 29, 2015 at 21:19
  • This actually makes a lot more sense to use for changing the interval time.
    – Jash Jacob
    Nov 1, 2015 at 6:08
  • I am noticing an issue with this method. With an interval of 10 minutes in data-interval the carousel simply doesn't slide. Works for smaller intervals. Not sure why. May 5, 2017 at 19:04
116

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.

2
  • For some reason, only the latter works for me. Thanks. Jun 28, 2018 at 17:28
  • @MindsectTeam There are a number of things that are at play. If you need to use the JS version of it, create a question with a minimal reproducible example and we can try to get to the bottom of it. :)
    – blurfus
    Jun 28, 2018 at 17:53
7

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">
5
        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>
2

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
       <div class="carousel-inner text-right">
                  <div class="carousel-item active text-center" id="first"  data-interval="1000" >
                    <img src="images/slide-1.gif" alt="slide-1">
                  </div>
                  <div class="carousel-item  text-center" id="second"  data-interval="2000" >
                    <img src="images/slide-2.gif" alt="slide-2">
                  </div>
                  <div class="carousel-item  text-center" id="third"  data-interval="3000" >
                    <img src="images/slide-3.gif" alt="slide-3">
                  </div>
                  <div class="carousel-item text-center" id="four"  data-interval="5000" >
                    <img src="images/slide-4.gif" alt="slide-4">
                  </div>
                </div>

You can also change different slides.

1
  • you can change diffrent diffrent slides Feb 3, 2021 at 11:35
0

You can add 'bs' in between data and interval (data-bs-interval="10000"), this works on newer version of Bootstrap.

Not the answer you're looking for? Browse other questions tagged or ask your own question.