采用延时的方法,取节点.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>