mirror of
https://github.com/568071718/creator-collection-view
synced 2025-04-20 16:18:41 +00:00
Merge ecb0ce3b494a6e4a9228a4ef5cd61db80a351003 into a7834bcf15a6ea4ab66207248d4f1d4c23f4a93f
This commit is contained in:
commit
08df7b143a
@ -1237,6 +1237,37 @@ export class YXCollectionView extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 滚动到指定索引位置
|
||||
* @param index 要滚动到的位置索引(从0开始)
|
||||
* @param timeInSecond 滚动动画时间(秒)
|
||||
* @param attenuated 是否带有衰减效果
|
||||
*/
|
||||
scrollToIndex(index: number, timeInSecond: number = 0, attenuated: boolean = true) {
|
||||
if (index < 0) return;
|
||||
|
||||
let currentIndex = 0;
|
||||
let targetIndexPath: YXIndexPath = null;
|
||||
|
||||
// 遍历所有section找到对应索引的位置
|
||||
for (let section = 0; section < this.getNumberOfSections(); section++) {
|
||||
const itemsInSection = this.getNumberOfItems(section);
|
||||
|
||||
if (currentIndex + itemsInSection > index) {
|
||||
// 找到目标索引所在的section和item
|
||||
const item = index - currentIndex;
|
||||
targetIndexPath = new YXIndexPath(section, item);
|
||||
break;
|
||||
}
|
||||
|
||||
currentIndex += itemsInSection;
|
||||
}
|
||||
|
||||
if (targetIndexPath) {
|
||||
this.scrollTo(targetIndexPath, timeInSecond, attenuated);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生命周期方法
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user