gpt4 book ai didi

javascript - 猫头鹰旋转木马 : Run function when last slide is reached

转载 作者:数据小太阳 更新时间:2023-10-29 05:43:24 25 4
gpt4 key购买 nike

我正在尝试在到达轮播的最后一张幻灯片时运行一个函数。我已经设法使用 afterInit 和 afterMove 回调来循环轮播项目,但我只需要能够在循环结束时运行一个函数。

希望你能帮到你。

插件:http://owlgraphic.com/owlcarousel/#customizing

slideshow.owlCarousel({
navigation: false, // Show next and prev buttons
slideSpeed: 300,
paginationSpeed: 400,
singleItem: true,
autoPlay: false,
stopOnHover: false,
afterInit : cycle,
afterMove : moved,
});

function cycle(elem){
$elem = elem;
//start counting
start();
}

function start() {
//reset timer
percentTime = 0;
isPause = false;
//run interval every 0.01 second
tick = setInterval(interval, 10);
};

function interval() {
if(isPause === false){
percentTime += 1 / time;
//if percentTime is equal or greater than 100
if(percentTime >= 100){
//slide to next item
$elem.trigger('owl.next')
}
}
}

function moved(){
//clear interval
clearTimeout(tick);
//start again
start();
}

最佳答案

我找不到任何 onEnd 处理程序。

但是您可以使用 afterMove 事件通过访问轮播实例属性 currentItemitemsCount 来检查显示的元素是否是最后一个。

引用:

var owl = $(".owl-carousel").data('owlCarousel');

代码:

// carousel setup
$(".owl-carousel").owlCarousel({
navigation: false,
slideSpeed: 300,
paginationSpeed: 400,
singleItem: true,
autoHeight: true,
afterMove: moved,
});


function moved() {
var owl = $(".owl-carousel").data('owlCarousel');
if (owl.currentItem + 1 === owl.itemsAmount) {
alert('THE END');
}
}

演示:http://jsfiddle.net/IrvinDominin/34bJ6/

关于javascript - 猫头鹰旋转木马 : Run function when last slide is reached,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21112084/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com