Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fire event on Bootstrap carousel slide issue

I try to use this code to fire on an event upon carousel slide, but it fails to work for some reason. Any suggestions?

var $carousel = $('#carousel-showcase');
$carousel.carousel();

$carousel.bind('slide', function(e) {

  setTimeout( function(){
    var left = $carousel.find('.item.active.left');
    var right = $carousel.find('.item.active.right');
    if(left.length > 0) {
    $("#wrap").animate({
        backgroundPositionX: '+=50%'
    },0);
    }
    else if(right.length > 0) {
    $("#wrap").animate({
        backgroundPositionX: '-=50%'
    },0);
    }
  }, 500);
});
like image 462
sdvnksv Avatar asked Nov 21 '13 18:11

sdvnksv


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 fires immediately when the slide instance method is invoked?

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.

How do I make Bootstrap carousel not slide automatically?

Use the [interval]="'0'" input. This will disable the auto-sliding feature. Here's the link to the Carousel Documentation.

How do I stop hover on carousel?

The data-pause attribute pauses the carousel from going through the slides when the mouse pointer enters the carousel. In this example, we have set pause to "hover" (default), which will stop the slide when your mouse pointer enters the carousel.


1 Answers

Bootstrap 3 changed the 'slide' event to 'slide.bs.carousel'. Change to this and it should work (assuming that is your only issue):

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

See this question.

like image 129
ringstaff Avatar answered Oct 14 '22 18:10

ringstaff