jQuery Bootstrap 轮播幻灯片问题上的火灾事件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20129290/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 00:59:31  来源:igfitidea点击:

Fire event on Bootstrap carousel slide issue

jquerytwitter-bootstrapcarouselslide

提问by sdvnksv

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);
});

回答by ringstaff

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

Bootstrap 3 将 'slide' 事件更改为 'slide.bs.carousel'。更改为此,它应该可以工作(假设这是您唯一的问题):

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

See this question.

看到这个问题