本文原创发布在华为开发者社区。
介绍
本示例使用Swiper(滑块视图容器)实现卡片轮播的功能。
效果预览
使用说明
卡片数据来自预置用例,可根据实际情况自行修改。同时可以初始化偏移量列表。
实现思路
首先设置卡片数据源,以及卡片索引值,之后通过Swiper实现卡片轮播。核心代码如下:
Swiper() {
LazyForEach(this.data, (item: CardInfo, index: number) => {
CardComponent({
cardInfo: item,
cardTotalLength: this.data.totalCount(),
cardIndex: index,
showingCard: this.currentSwiperIndex
})
})
}
.index($$this.currentSwiperIndex)
.loop(true)
.indicator(false)
.itemSpace(20)
.displayCount(3)
.duration(Constants.DURATION)
.curve(Curve.Friction)
.onChange((index) => {
this.currentSwiperIndex = index
})
.height('100%')
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。