实现卡片轮播鸿蒙示例代码

鸿蒙场景化示例代码技术工程师
发布于 2025-3-6 16:13
浏览
0收藏

本文原创发布在华为开发者社区

介绍

本示例使用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%')
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.

分类
收藏
回复
举报
回复
    相关推荐