Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fire event on carousel slide (not slid) event, Bootstrap 3

Bootstrap 2 seems to work fine handling the slide event (see this question) with the following code:

$('#myCarousel').bind('slide', function (e) {
    console.log('slide event!');
});

I cannot, however, get the same things to work in Bootstrap 3 (see this fiddle). Anyone know why?

like image 405
ringstaff Avatar asked Nov 21 '13 20:11

ringstaff


People also ask

Why is Bootstrap carousel not sliding?

In browsers where the Page Visibility API is supported, the carousel will avoid sliding when the webpage is not visible to the user (such as when the browser tab is inactive, the browser window is minimized, etc.).

Which event is fired when the carousel has completed its slide transition?

All carousel events are fired at the carousel itself (i.e. at the <div class="carousel"> ). This event fires immediately when the slide instance method is invoked. This event is fired when the carousel has completed its slide transition.

How do I make bootstrap carousel not slide automatically?

How do I stop bootstrap carousel Auto Slide? Use the [interval]="'0'" input. This will disable the auto-sliding feature.

Which class is used to determine the current slide in bootstrap?

Bootstrap's carousel class exposes two events for hooking into carousel functionality. Both events have the following additional properties: direction : The direction in which the carousel is sliding (either "left" or "right" ). relatedTarget : The DOM element that is being slid into place as the active item.


2 Answers

Actual event namespace for slide according to bootstrap3 implementation is slide.bs.carousel as opposed to slide which was the one acc: to BS2, also use slid.bs.carousel to track completion of slide (though slid seems to work.)

So try:

$('#myCarousel').bind('slide.bs.carousel', function (e) {
    console.log('slide event!');
});

Demo

like image 129
PSL Avatar answered Sep 16 '22 15:09

PSL


On Slide before

h('#HomeSlider').bind('slide.bs.carousel', function (e) {
   alert(h('#HomeSlider .item.active').html());
});

On Slide After

h('#HomeSlider').on('slid.bs.carousel', function (e) {
   alert(h('#HomeSlider .item.active').html());
});
like image 23
Harikaran K Avatar answered Sep 20 '22 15:09

Harikaran K