小程序 滚动wx.pageScrollTo

API:https://developers.weixin.qq.com/miniprogram/dev/api/wx.pageScrollTo.html

wx.pageScrollTo

在小程序的开发过程中,有个功能是点击后需要往view层中添加数据内容,在添加后需要将内容滚动到最下面一条,以便有更好的用户体验。

页面布局是:

最外层<view class="box">内容</view>

底部有输入框固定着<view class='footer'></footer>

为了解决抖动页面的问题:如果页面中有fixed定位的元素,定位的元素会跟随页面滚动,再回到位置上,产生页面抖动 => 在代码中加入duration:0

滚动到底部代码如下 

  wx.createSelectorQuery().select('.box').boundingClientRect(function (rect) {
      // 使页面滚动到底部
      // console.log(rect.bottom)
      // console.log(rect.height)
      wx.pageScrollTo({
        scrollTop: rect.height,
        duration: 0
      })
    }).exec()

参考博文 转自:https://blog.csdn.net/qq_41080490/article/details/80267742

原文地址:https://www.cnblogs.com/dudu123/p/10412379.html