onPageScroll在安卓和iOS上渲染的不同表现
- 当前 Bug 的表现(可附上截图)
想在文章阅读页,加上一个顶部阅读进度条。使用onPageScroll实时判断滚动条距离,然后得出进度比例。
但是,iOS渲染正常,安卓就很卡顿,有几秒的延迟,在社区寻找解决方案,发现:
{ "usingComponents": {}} |
配置加上这个,安卓就正常了,但是iOS又开始卡顿。
- 预期表现
希望有办法可以同时iOS和安卓都能onPageScroll实时渲染
-
复现路径
-
提供一个最简复现 Demo
<view class="read-progress" hidden="{{hideProgress}}"> <progress stroke-width="6" activeColor="#57b4fc" percent="{{percent}}" /></view><view class="container" id="topic-detail"></view> |
onPageScroll: function (e) { this.updateViewHeight() this.updateProgress(e.scrollTop)},updateProgress: function (st) { var h = this.data.pageHeight if (h > 0 && st > 100) { var p = Math.floor(100 * (st - 100) / (h - 850)) this.setData({ hideProgress: false, percent: p }) } else { this.setData({ hideProgress: true }) }},updateViewHeight: function () { if (this.data.pageHeight === 0) { var that = this var query = wx.createSelectorQuery() query.select('#topic-detail').boundingClientRect(function (res) { that.setData({ pageHeight: res.height }) }).exec() }} |
