Cocos Creator教程:实现PageView组件的自动翻页效果 | 南锋

南锋

南奔万里空,脱死锋镝余

Cocos Creator教程:实现PageView组件的自动翻页效果

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
let pageList = this._view._PageC_List;
let pageCount = pageList.getPages().length; // 获取翻页容器长度
let duration = 3; // 自动翻页时间,s
let currentPageIndex = 0; // 当前页数
let direction = 1; // 翻页方向
let scrollTiem = 1; // 翻页时间
pageList.schedule(()=>{
if(currentPageIndex === pageCount-1){
direction = -1;
}else if(currentPageIndex === 0){
direction = 1;
}
currentPageIndex += direction;
pageList.scrollToPage(currentPageIndex,scrollTiem);
},duration)
+