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

javascript - Bootstrap carousel ignoring data-interval attribute - Stack Overflow

programmeradmin1浏览0评论

Here's my markup:

<div id="carousel-example-generic" class="carousel slide" data-interval="false" data-pause="hover">
        <!-- Indicators -->
        <ol class="carousel-indicators">
            <li data-target="#carousel-example-generic" data-slide-to="0"></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">
                <div style="height:200px;">Slide 1</div>
                <div class="carousel-caption">
                    ...
                </div>
            </div>
            <div class="item">
                <div style="height:200px;">Slide 2</div>
                <div class="carousel-caption">
                    ...
                </div>
            </div>
            <div class="item ">
                <div style="height:200px;">Slide 3</div>
                <div class="carousel-caption">
                    ...
                </div>
            </div>
        </div>

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

I am using bootstrap v3.0.3, and yet the carousel still starts scrolling after page is loaded. I have also tried including:

$(function () {
    $(".carousel").carousel({ interval: false });
});

I've done this with and without the data-interval attribute, all to no avail. The carousel automatically starts scrolling after page is loaded. I have seen other questions about this but they were all referring to older version and implied it has been fixed by now.

Any ideas please?

Here's my markup:

<div id="carousel-example-generic" class="carousel slide" data-interval="false" data-pause="hover">
        <!-- Indicators -->
        <ol class="carousel-indicators">
            <li data-target="#carousel-example-generic" data-slide-to="0"></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">
                <div style="height:200px;">Slide 1</div>
                <div class="carousel-caption">
                    ...
                </div>
            </div>
            <div class="item">
                <div style="height:200px;">Slide 2</div>
                <div class="carousel-caption">
                    ...
                </div>
            </div>
            <div class="item ">
                <div style="height:200px;">Slide 3</div>
                <div class="carousel-caption">
                    ...
                </div>
            </div>
        </div>

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

I am using bootstrap v3.0.3, and yet the carousel still starts scrolling after page is loaded. I have also tried including:

$(function () {
    $(".carousel").carousel({ interval: false });
});

I've done this with and without the data-interval attribute, all to no avail. The carousel automatically starts scrolling after page is loaded. I have seen other questions about this but they were all referring to older version and implied it has been fixed by now.

Any ideas please?

Share Improve this question edited Jan 1, 2014 at 22:22 hkk 2,1491 gold badge26 silver badges48 bronze badges asked Jan 1, 2014 at 21:07 codedogcodedog 2,5089 gold badges39 silver badges67 bronze badges 3
  • 1 Seems to work fine on 3.0.3 - bootply./103352 Do you have any other JavaScript code or other carousels on the same page? – Carol Skelly Commented Jan 1, 2014 at 21:50
  • 1 You are absolutely right! There were some scripts for other plugins referenced before my script. They were leftovers from another site I built some time ago. The perils of copy'n'paste! It works just fine thanks :) What's the mon practice here? I can't vote your ment as an answer. Do I just delete this question? – codedog Commented Jan 1, 2014 at 21:57
  • I added my ment as an solution/answer. Pls accept so that others know your question is resolved. Thanks! – Carol Skelly Commented Jan 1, 2014 at 22:17
Add a ment  | 

1 Answer 1

Reset to default 1

Your carousel markup is correct for 3.0.3 (http://bootply./103352)

Make sure there is not other JavaScript code or other carousels on the same page.

发布评论

评论列表(0)

  1. 暂无评论