jfrosty jfrosty - 2 months ago 10
jQuery Question

How to disable carousel cycle, when user clicks indicators or carousel controls?

Using Bootstrap ready made carousel, I want to disable the automated cycle feature when the user clicks on the indicators or controls (next/prev buttons). So, if user clicks on the 'next' button, the carousel will now be manual. Not strong in jQuery, but this was my attempt.

$('#myCarousel').click(function() {
$(this).stop();
});

Answer

You can access the interval option via the carousel's .data() object, and set it to false..

$('#myCarousel').click(function() {
  $(this).data('carousel').options.interval=false;
});

Demo: http://www.bootply.com/65091