根据文本高度来判断盒子的隐藏与否(微信小程序)

html:
<text id='every' class="{{long}} {{isFold?'hide':'show'}}">{{listdata.content}}</text>  
//给文本id            class变量
JS:
    var query = wx.createSelectorQuery();
    query.select('#every').boundingClientRect(function(rect) {
      wx.getSystemInfo({
        success: function(res) {
        let resHeight = (rect.height * (750 / res.windowWidth));//转换单位PX
        console.log(resHeight)
        if (resHeight > 200) {
        that.setData({
          long:"long-dec",
          showlong: true
        })
      } 
      else{
        that.setData({
        long: "",
        showlong: false
        })
      }
   }
  })
}).exec();

猜你喜欢

转载自www.cnblogs.com/Glant/p/10691226.html