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

举报
水滴石轩 发表于 2025/03/07 11:21:30 2025/03/07
【摘要】 private swiperController: SwiperController = new SwiperController() Swiper(this.swiperController) { ForEach(this.list, (item: Resource, index) => { RelativeContainer() { Image(ite...
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 ---------------

    后面会继续补充不足之处。

【声明】本内容来自华为云开发者社区博主,不代表华为云及华为云开发者社区的观点和立场。转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。