首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >HarmonyOS NEXT 轮播组件Swiper的学习和总结

HarmonyOS NEXT 轮播组件Swiper的学习和总结

原创
作者头像
水滴石轩
修改2025-03-16 19:22:43
修改2025-03-16 19:22:43
2910
举报
代码语言:javascript
复制
private swiperController: SwiperController = new SwiperController()
 Swiper(this.swiperController) {
     ForEach(this.list, (item: Resource, index) => {
       RelativeContainer() {
         Image(item)
           .width('100%')
           .draggable(false)
       }
       .width('100%')
       .height('100%')

     })
   }
   .index($$this.currentIndex)
   .loop(this.isLoop)
   .autoPlay(this.isAutoPlay)
   .interval(5000)
   .indicator(false)
   .vertical(false)
   .displayCount(2)
   .effectMode(EdgeEffect.None)
   .backgroundColor(0x00ffff)
   .width('100%')
   .height('100%')
   .onGestureSwipe((index, e) => {
     console.debug(`swiper onGestureSwipe index:${index} e:${e} `);
   })
   .onContentDidScroll((selectedIndex: number, index: number, position: number, mainAxisLength: number) => {
     console.debug(`swiper selectedIndex:${selectedIndex} index:${index} position:${position} mainAxisLength:${mainAxisLength}`);
   })

  • $$this.currentIndex 使用$$绑定swiper播放展示的索引和当前类的索引,实现双向同步
  • loop 控制是否循环播放,默认值为true
  • autoPlay 控制是否自动轮播,默认值为false
  • interval 控制播放间隔,默认值为3000,单位毫秒
  • indicator 根据需要设置导航点
  • swiperController 控制器,滑动轮播,除了自动播放,也可以使用控制器设置播放,swiperController.showNext()、swiperController.showPrevious()
  • vertical 控制轮播方向,true表示垂直方向;false表示水平方向,默认值为false。
  • displayCount 控制每一页展示几个播放页 ----------------- end --------------- 后面会继续补充不足之处。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档