How to stop carousel loading on the first cycle

I want the slider to start sliding, and it should stop in the first loop on the first image of the slide / carousel.

var imgCount = 3;
$('#myCarousel').carousel({
    interval: 2500
});
$('#myCarousel').bind('slid',function(){
    imgCount--;
    if(imgCount == 3)
        $('#myCarousel').carousel('pause');  
});

I also tried the following code.

$('#myCarousel').carousel({
    interval: 2500
});
$('#myCarousel').bind('slid',function(){
    var count = 3;

    count--;
    if(count == 0)
    {

        slide.stopAutoPlay();
    }

});

For some reason it does not work. I am using a string tag immediately after the source script download file.

+4
source share
1 answer

The wrapper parameter is used to stop the carousel in the first cycle. But it remains on the last page after completion.

<div id="carousel-example" class="carousel slide" data-ride="carousel" data-wrap="false">

or

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

If you want it to stop on a specific slide, this code will help you achieve this.

var count = 1;

$('.carousel').carousel();
$('.carousel').on('slid.bs.carousel', function () {
    count--;
    if (count <= 0) {
        $('.carousel').carousel('pause');
    }
});

{Edit}

Also, if you want to reset the carousel and go to the first page after stopping, add it after a pause

var count = 1;

$('.carousel').carousel();
$('.carousel').on('slid.bs.carousel', function () {
    count--;
    if (count <= 0) {
        $('.carousel').carousel('pause');
        // Reset the carousel position
        setTimeout(function () {
            $('.carousel').carousel(0);
        }, 200);
    }
});

-, , .

+3

All Articles