0

I have a pause button in my carousel and , it is not working.

My requirement is that when author will click on pause button then the Carousel slide will be stopped and when they again click on pause button then the slide will again start rotating from starting 3 seconds.

I have written below code.

Landing Page Carousel Testing Here 1}"> $(function() { $('#myCarousel').carousel({ interval: 3000, pause: "false" }); $('#pauseButton').click(function() { $('#myCarousel').carousel('pause'); }); });

It should pause and play from 3000 seconds

crazymatt
  • 3,266
  • 1
  • 25
  • 41
sonu
  • 21
  • 3

1 Answers1

0

The button has two states that aren't expressed in the code. One is for when the carousel is active, and one when it isn't. This can be expressed using classes that you add to or remove from your HTML element using JQuery:

$('#pausButton').click(function(){
    if($(this).hasClass('active')){
        $('#myCarousel').carousel({ interval: 3000, pause: "false" });
        $(this).removeClass('active')
    } else {
        $('#myCarousel').carousel('pause');
        $(this).addClass('active')
    }
});

hope it helped, state taken from Keep button in active state until clicked upon again

Linh
  • 418
  • 4
  • 9