小程序跳转页面滚动到指定区域

例如到首页后直接滚动到有list样式名的位置:

代码1

      const query = wx.createSelectorQuery()
      query.select('.list').boundingClientRect()
      query.selectViewport().scrollOffset()
      query.exec(function(res) {
    
    
        // console.log(res[0].top)
        if (res[0]) {
    
    
          wx.pageScrollTo({
    
    
            scrollTop: res[0].top,
            duration: 300
          })
        }
      })

如果是指定页面跳转才执行以上代码:
可以在指定页面

wx.setStorageSync('homeLocation','111')

首页

 if (wepy.getStorageSync('homeLocation')) {
    
    
      wx.removeStorageSync('homeLocation')
      。。。代码1
}

猜你喜欢

转载自blog.csdn.net/qq_26642611/article/details/108508738