Html 如何阻止 Bootstrap 轮播自动滑动?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26133618/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 02:48:49  来源:igfitidea点击:

How to stop Bootstrap carousel from autosliding?

htmltwitter-bootstrapcarousel

提问by user3123222

I have built a bootstrap video carousel. It is working just fine but, the only problem I have is the carousel keeps sliding to the next slide after 5 seconds. How do I make it stop autosliding and only slide when the user clicks on the left or right arrows? I have pasted the code below.

我已经建立了一个引导视频轮播。它工作得很好,但我唯一的问题是旋转木马在 5 秒后一直滑动到下一张幻灯片。如何让它停止自动滑动并仅在用户单击向左或向右箭头时滑动?我已经粘贴了下面的代码。

    <div class="container">
        <div id="carousel-example-generic" class="carousel slide" data-ride="carousel" data-pause=hover>
            <!-- Indicators -->
            <ol class="carousel-indicators">
                <li data-target="#carousel-example-generic" data-slide-to="0" class="active"></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 class="embed-responsive embed-responsive-16by9">
                        <video class="embed-responsive-item" autoplay muted id="homevid">
                            <source src="C:\Development Software\Sample Website\videos\Michael Vick 88 yard touchdown pass to DeSean Hymanson.mp4" />
                        </video>
                    </div>
                <div class="carousel-caption">

            </div>
        </div>
            <div class="item">
                <div class="embed-responsive embed-responsive-16by9">
                    <video class="embed-responsive-item" autoplay muted id="homevid">
                        <source src="C:\Development Software\Sample Website\videos\Vick to Jeremy Maclin for 50 Yard TD.mp4" />
                    </video>
                </div>

            </div>
            <div class="item">
                <div class="embed-responsive embed-responsive-16by9">
                    <video class="embed-responsive-item" autoplay muted id="homevid">
                        <source src="C:\Development Software\Sample Website\videos\Michael Vick Scramble Plays vs Rams 2011.mp4" />
                    </video>
                </div>
          </div>
    </div>

回答by Brian Dillingham

By adding data-interval="false"

通过添加 data-interval="false"

<div id="carousel-example-generic" class="carousel slide" data-interval="false" data-ride="carousel" data-pause="hover" >

From the documentation

文档

Option - Interval - ..If false, carousel will not automatically cycle.

Option - Interval - ..如果为false,carousel不会自动循环。

回答by Vinod Kumar

There are two ways.

有两种方法。

1.

1.

In your HTML codes, you need to use only data-interval="false"

在您的 HTML 代码中,您只需要使用data-interval="false"

<div id="your-carousel-id" class="carousel slide" data-interval="false">
    .....
</div>
<div id="your-carousel-id" class="carousel slide" data-interval="false">
    .....
</div>

2.

2.

If you want to do with the help of Jquery then you need to add.

如果你想借助 Jquery 来做,那么你需要添加。

//document ready
$(document).ready(function(){
    //Event for pushed the video
    $('#your-carousel-id').carousel({
        pause: true,
        interval: false
    });
});
//document ready
$(document).ready(function(){
    //Event for pushed the video
    $('#your-carousel-id').carousel({
        pause: true,
        interval: false
    });
});

Thanks :)

谢谢 :)

回答by Abhay Singh

To stop the autoplay is by just removing the attribute data-ride=”carousel”from the htmlcode

要停止自动播放,只需从 htmlcode 中删除属性data-ride="carousel"

<div id="carousel-example" class="carousel slide" data-ride="carousel">....</div>

There is another way to stop autoplay just add below code in your js file

还有另一种停止自动播放的方法,只需在 js 文件中添加以下代码

$(window).load(function() {
    $('.carousel').carousel('pause'); 
});

回答by Tariqul_Islam

Paste this code on your custom Javascript file.

将此代码粘贴到您的自定义 Javascript 文件中。

$('.carousel').carousel({ interval: false });

$('.carousel').carousel({ interval: false });