当到达轮播的最后一张幻灯片时,我试图运行一个函数。我已经设法使用 afterInit 和 afterMove 回调来循环轮播项目,但我只需要能够在循环结束时运行一个函数。
希望你能帮忙。
Plugin: http://owlgraphic.com/owlcarousel/#customizing 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
通过访问轮播实例属性来检查显示的元素是否是最后一个的事件currentItem
and itemsCount
.
Ref:
var owl = $(".owl-carousel").data('owlCarousel');
Code:
// 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');
}
}
Demo: http://jsfiddle.net/IrvinDominin/34bJ6/ http://jsfiddle.net/IrvinDominin/34bJ6/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)