微信小程序 滚动到页面底部or顶部 wx.pageScrollTo和wx.createSelectorQuery

scrollBottom() {
      wx.createSelectorQuery()
        .select("#charRoom")
        .boundingClientRect(function(rect) {
          wx.pageScrollTo({
            scrollTop: rect.bottom,
            duration:0
          });
        })
        .exec();
}
复制代码

如果页面是静态的话,放在onReady生命周期,让页面准备好后滚动到底部。如果是动态数据,应该放在请求返回后执行

  • wx.createSelectorQuery该api获取到页-面的尺寸,然后用wx.pageScrollTo滚动到对应位置

    • .select('#id') 选择要滚动的元素id

    • .boundingClientRect 添加节点的布局位置的查询请求。返回四角坐标位置和大小

  • wx.pageScrollTo小程序api,滚动页面位置。

转载于:https://juejin.im/post/5cff56476fb9a07ea33c0c23

猜你喜欢

转载自blog.csdn.net/weixin_33735676/article/details/93178951