HarmonyOS Arkts中的Scroll组件如何监听滚动条滚动事件获取滚动条高度

发布于 3 个月前 作者 itying888 204 次浏览 最后一次编辑是 2 个月前 来自 分享

HarmonyOS Arkts中的Scroll组件如何监听滚动条滚动事件获取滚动条高度呢?下面我们一起看看。

HarmonyOS Arkts中的Scroll组件可以通过监听onScroll事件来获取滚动条滚动的高度。

HarmonyOS 门实战系列教程(基础免费学):https://www.itying.com/goods-1193.html

最新HarmonyOS系列教程在线学习地址:https://www.bilibili.com/video/BV1sc411q7Bd

scroller: Scroller = new Scroller()

 Scroll(this.scroller) {
        Column() {
          this.SwiperWidget()

          this.BestCategoryWidget()
          Text(this.message)
          this.AdWidget()
          this.HotSellingGoods()

        }.width("100%")
      }.padding({
        bottom: "200lpx"
      }).onScroll((offsetX: number,offsetY:number) => {
        this.message=this.scroller.currentOffset().yOffset+""
      })

this.scroller.currentOffset().yOffset可以获取距离顶部的高度

HarmonyOS 门实战系列教程(基础免费学):https://www.itying.com/goods-1193.html

最新HarmonyOS系列教程在线学习地址:https://www.bilibili.com/video/BV1sc411q7Bd

回到顶部