美文网首页
微信小程序---列表的动态计算scrollview高度

微信小程序---列表的动态计算scrollview高度

作者: 不可雕的板蓝根 | 来源:发表于2018-08-22 16:39 被阅读0次

采用延时的方法,取节点.headerView为所选视图的class,取windowHeight的高度,单位为px,节点的获取值单位也为px,在wxml文件中单位也需要用px的单位,否则计算的值不对。

setTimeout(function () {
      let query = wx.createSelectorQuery()
      query.select('.headerView').boundingClientRect(function (res) {
        //在这里做计算,res里有需要的数据
        console.log('======', res, res.bottom, (app.globalData.windowHeight - res.bottom))
        that.setData({
          scrollHeight: (app.globalData.windowHeight - res.bottom)
        })
      }).exec()
    }, 400)
<scroll-view style='height:{{scrollHeight}}px' scroll-y>

相关文章

网友评论

      本文标题:微信小程序---列表的动态计算scrollview高度

      本文链接:https://www.haomeiwen.com/subject/ukyyiftx.html