Wechat applet to get the height of the element

Get the height (unit px)

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

Get the height (in 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();

Guess you like

Origin blog.csdn.net/qq_29483485/article/details/127447830