最佳答案
以下内容应该有效。
setInterval(function () {
myScroll.scrollToPage('next', 0, 400);
}, 2000);
您当然必须检查何时到达轮播的末尾 (curPageX)。
======
更新:在 iScroll 5 中,代码略有更改,您需要执行类似的操作来启动自动循环;同时可以选择在用户交互(触摸/滑动)后停止自动滚动。
/* start auto-scrolling */
myInterval = setInterval(autoScroll, 5000);
/* function handles the looping of the carousel */
function autoScroll() {
var currPage = myScroll.currentPage.pageX + 1;
if(currPage == myScroll.pages.length) {
myScroll.goToPage(0, 0, 250);
} else {
myScroll.goToPage(currPage, 0, 250);
}
}
/* stops auto-scrolling on swipe (using jQuery .on() method) */
myScroll.on('beforeScrollStart', function() {
clearInterval(myInterval);
});
希望对偶然发现此页面的人有所帮助!
关于jquery - iScroll 自动循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9271947/