版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010095372/article/details/80902154
在小程序中实现scroll-view上拉下滑触发必须设置它自身的高度,有的时候还有别的元素,不一定就是整个屏幕,这时候我们就得计算它的实际高度了,以至于能够动态的适应不同的手机屏幕
计算高度这样的
wx.getSystemInfo({
success: function (res) {
console.info(res.windowHeight);
let height = res.windowHeight;
wx.createSelectorQuery().selectAll('#sousuode').boundingClientRect(function (rects) {
rects.forEach(function (rect) {
console.info(res.windowHeight - rect.bottom);
that.setData({
scrollHeight: res.windowHeight - rect.bottom
});
})
}).exec();
}
});
其中 sousuode 就是其他元素所占有的高度,用屏幕高度减一下就好了。