微信小程式 上拉下滑觸發,計算實際scroll-view的高度
阿新 • • 發佈:2018-11-12
在小程式中實現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 就是其他元素所佔有的高度,用螢幕高度減一下就好了。