如题:HarmonyOS Scroll组件回调事件onScroll(event: (xOffset: number, yOffset: number) =\> void),返回的参数xOffset/yOffset,数据不对?
问题场景Scroll组件回调事件onScroll(event: (xOffset: number, yOffset: number) =\> void),经测试,返回的xOffset,yOffset数值并不是滚动偏移量,而是滚动速度调用Scroll组件回调函数onScroll,获取参数yOffset获取到的数值发现与滚动偏移量无关,且经常为负数,经验证数值为滚动速度onscroll事件会丢失精度,建议用currentOffset来获取当前的滚动偏移量实现吸顶效果,代码如下:.onScroll((xOffset: number, yOffset: number) => { // console.log(yOffset.toString()) // this.scrollY += yOffset // this.tabPosY = this.topAreaHeight - this.scrollY <= 0 ? 0 : this.topAreaHeight - this.scrollY this.tabPosY = this.topAreaHeight - this.scroller.currentOffset() .yOffset <= 0 ? 0 : this.topAreaHeight - this.scroller.currentOffset() .yOffset // console.log(TAG, `Scrollview is scrolling, scrollY: ${this.scrollY}, tabPosY: ${this.tabPosY}`); })
问题场景
Scroll组件回调事件onScroll(event: (xOffset: number, yOffset: number) =\> void),经测试,返回的xOffset,yOffset数值并不是滚动偏移量,而是滚动速度
调用Scroll组件回调函数onScroll,获取参数yOffset
获取到的数值发现与滚动偏移量无关,且经常为负数,经验证数值为滚动速度
onscroll事件会丢失精度,建议用currentOffset来获取当前的滚动偏移量实现吸顶效果,代码如下: