微信小程序获取元素的高度

获取 高度 (单位px)

let query = wx.createSelectorQuery();
query.select('.content').boundingClientRect(rect=>{
  let height = rect.height;
  console.log(height);
}).exec();
// .exec() 不加不执行

获取 高度 (单位rpx)

let query = wx.createSelectorQuery();
query.select('.content').boundingClientRect(rect=>{
  let clientHeight = rect.height;
  let clientWidth = rect.width;
  let ratio = 750 / clientWidth;
  let height = clientHeight * ratio;
  console.log(height);
}).exec();

猜你喜欢

转载自blog.csdn.net/qq_29483485/article/details/127447830