Twitter Bootstrap Carousel autoplay on load

前端 未结 10 1017
天命终不由人
天命终不由人 2021-02-07 03:15

Using the twitter bootstrap framework, how is it possible to invoke the carousel to \'auto slide.\' Meaning when the page loads, the carousel automatically scrolls.

I ha

10条回答
  •  不知归路
    2021-02-07 04:13

    you should do as the Twitter Bootstrap Documentation says about Carousel, so set the first Carousel slide item with class="active" and initialize the js for the carousel in this way:

    $(function(){
        $('.carousel').carousel({
          interval: 2000
        });
    });
    

    then if it's not enough (but this never happened to me) use the bruteforce triggering the click hover the carousel control buttons like this:

    $(function(){
    $('.carousel').carousel({
          interval: 2000
        });
    $('.carousel-control.right').trigger('click');
    });
    

    but this is just a not-needed trick, really, just follow the documentantion!

提交回复
热议问题