小程序滚动到一个位置

2020-06-09  本文已影响0人  糖醋里脊120625

小程序滚动到一个位置

 input(e){
    console.log(e.currentTarget.dataset.id)
    if (e.currentTarget.dataset.id != 1) {
      this.setData({
        isShow: true,
      })
    }
    const query = wx.createSelectorQuery()
    query.select('#main').boundingClientRect()
    query.selectViewport().scrollOffset()
    query.exec(height => {
      console.log(height)
      height[0].top       // #the-id节点的上边界坐标
      height[1].scrollTop // 显示区域的竖直滚动位置
      wx.pageScrollTo({
        scrollTop: height[0].height,
        duration: 300
      });
    })
  },
上一篇 下一篇

猜你喜欢

热点阅读