微信小程序获取某个元素的高度和宽度

作者: web 发布时间: 2019-05-16 浏览: 3051 次 编辑

微信小程序获取某个元素的高度和宽度

js页面

//创建节点选择器
    var query = wx.createSelectorQuery();
    //选择id
    var that = this;
    query.select('.every').boundingClientRect(function (rect) {
      // console.log(rect.width)
      that.setData({
        height: rect.width + 'px'
      })
    }).exec();

wxml页面

<view class='every' style='height:{{height}}'></view>