小程序如何自动滚动到页面底部

1,990 阅读1分钟

1. scroll-view作为滚动内容容器

利用scroll-into-view将最后一个子视图的id作为目标对象

2. 常规view作为滚动内容容器

1.给盒子定义一个id为x_chat;(其他样式,按需定义)

* <view id="x_chat" class="dialog" >
* </view>

2.滚动到页面底部

pageScrollToBottom: function() {
  console.log("滚动")
  let that = this;
  wx.createSelectorQuery().select('#x_chat').boundingClientRect(function(rect) {
    console.log(rect)
    wx.pageScrollTo({
     //不要使用rect.bottom,亲测滚动距离过高时,成为了一个定值,不准确
      scrollTop: rect.height,
      duration: 100
    })
  }).exec()
},