微信小程序获取节点的位置信息

/**
 * 生命周期函数--监听页面加载
 */
onLoad: function (options) {
  let _this = this;
  let query = wx.createSelectorQuery()
  query.select('.wrap').boundingClientRect()
  query.selectViewport().scrollOffset()
  query.exec(function (res) {
    console.log(res)
    // res[0].top       // 节点的上边界坐标
    // res[1].scrollTop // 显示区域的竖直滚动位置
    _this.setData({
      wrapTop: res[0].top 
    })
    console.log(_this.data.wrapTop);
  })
},

发布了77 篇原创文章 · 获赞 7 · 访问量 9131

猜你喜欢

转载自blog.csdn.net/Misnice/article/details/102972326