微信小程序获取元素节点的宽高

// wxml文件中

<view class="card-user" style="height:{
   
   {card_height}}px;">

    // 内容

</view>
data: {
    // 盒子高度
    card_height:0
},
// 设置盒子高度
getCard_height(){
 var that = this
 //创建节点选择器
 var query = wx.createSelectorQuery();
 //选择class id
  query.select('.card-user').boundingClientRect(function (rect) {
   let card_height = rect.width*2/3
   that.setData({
    card_height:card_height
   })
  }).exec();
},

onShow() {
 this.getCard_height()
},

猜你喜欢

转载自blog.csdn.net/Achong999/article/details/130871371
今日推荐