微信小程序获取元素距离顶部的距离

id首位不能是数字,否则boundingClientRect()获取到的res会是null。

let id = `#${元素的id值}`
wx.createSelectorQuery().select(id).boundingClientRect(function(rect){
      // 节点的上边界坐标
      let top = rect.top;
      // 节点的下边界坐标
      let bottom = rect.bottom;
}).exec()
发布了258 篇原创文章 · 获赞 21 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/wsln_123456/article/details/104629437