Bootstrap carousel事件'只开除一个

bootstrap carousel event 'slide.bs.carousel' gets fired only ones

本文关键字:一个 事件 carousel Bootstrap      更新时间:2023-09-26

这是我的JavaScript:

$('#carousel-container').bind("slide.bs.carousel", function () {
    //reset
    $('.slideImg',this).css('min-height', '');
    //set
    var sliderHeight = $(this).height();
    $(this).css('min-height', sliderHeight + 'px');
    $(this).off("slide.bs.carousel");
    //set the max size for img
    $('.slideImg').css('max-height', (sliderHeight * 0.9) + 'px');
    $('#Hand_Side').css('max-height', (sliderHeight * 0.4) + 'px');
});
这是我的HTML:
<div id="carousel-container" class="carousel slide container" data-ride="carousel">
                            <!-- Wrapper for slides -->
                            <div class="carousel-inner" role="listbox">
                                <div id="slide1" class="item active">
                                </div>
                                <div id="slide3" class="item">
                                </div>
                           </div>
                        </div>

我不知道为什么,但是事件只在滑动第一张幻灯片之前被解雇。

我看到我错过了这一行

$(this).off("slide.bs.carousel");

这一行关闭了不应该再触发的事件