bootstrap carousel pause not working

坚强是说给别人听的谎言 提交于 2019-12-11 04:54:55

问题


I'm unable to invoke the 'pause' function on the Bootstrap (3.0.2) carousel. I've tried every way I can think of to refer to the carousel instance, but - no errors, no pause.

<script>
    var stepIndex = 3;
    $('.carousel').carousel({
        interval: 3000
    });
    $('#carousel-couples').on('slide.bs.carousel', function () {
        stepIndex--
        console.log("carousel stepping", stepIndex);
        if (stepIndex == 0) {
            console.log("supposedly pausing carousel");
            $('.carousel').carousel('pause');
        }
    })
</script>
</body>
</html>

回答1:


Calling pause on a carousel while its sliding does not seem to work. Instead use the slid.bs.carousel event runs once the slide has finished the transition and then your pause should work.

$('#carousel-couples').on('slid.bs.carousel', function () {
    ...
});


来源:https://stackoverflow.com/questions/20305701/bootstrap-carousel-pause-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!