添加到@antongorodezkiy 的答案中,有一种方法可以infiniteLoop: false
让幻灯片不断变化:使用onSlideAfter
最后一张幻灯片的事件,几秒钟后,您可以返回第一张幻灯片并重新启动auto
模式:
var pauseTime = 4000; //Time each slide is shown in ms. This is the default value.
var timeoutId;
var slider = $('.bxslider').bxSlider({
auto: true,
infiniteLoop: false,
pause: pauseTime,
onSlideAfter: function ($slideElement, oldIndex, newIndex) {
if (newIndex === slider.getSlideCount() - 1) { //Check if last slide
setTimeout(
function () {
slider.goToSlide(0);
slider.startAuto(); //You need to restart the "auto" mode
},
pauseTime //Use the same amount of time the slider is using
);
}
else { //In case the user changes the slide before the timeout fires
clearTimeout(timeoutId);
slider.startAuto(); //Doesn't affects the slider if it's already on "auto" mode
}
}
});
此解决方案与选项之间的区别在于infiniteLoop: true
,滑块不会像下一张一样平滑地过渡回第一张幻灯片,而是快速“倒回”直到到达第一张幻灯片。