小程序时光轴

监听滚动条位置 - 小程序

2019-04-16  本文已影响0人  侯工

更新前:

pageScrollToBottom: function () {
   wx.createSelectorQuery().select('#the-id').boundingClientRect(function (rect) {
     // 使页面滚动到底部
     wx.pageScrollTo({
       scrollTop: rect.bottom
     })
   }).exec()
 }

更新后:

pageScrollToBottom: function () {
  const query = wx.createSelectorQuery()
  query.select('#the-id').boundingClientRect()
  query.selectViewport().scrollOffset()
  query.exec(function (res) {
    res[0].top // #the-id节点的上边界坐标
    res[1].scrollTop // 显示区域的竖直滚动位置
  })
}
上一篇 下一篇

猜你喜欢

热点阅读