美文网首页
小程序滚动到一个位置

小程序滚动到一个位置

作者: 糖醋里脊120625 | 来源:发表于2020-06-09 18:00 被阅读0次

小程序滚动到一个位置

 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
      });
    })
  },

相关文章

网友评论

      本文标题:小程序滚动到一个位置

      本文链接:https://www.haomeiwen.com/subject/lcjetktx.html