wx.getSystemInfo和wx.createSelectorQuery()在有tabBar的情况下获取的可用高度都有误。
在onReady中获取,不要在onLoad中获取,可以在view中声明元素<view style=‘height:100%;width:100%;position:fixed;z-index:-100;’ id=‘getHeight’></view>
onReady:function(){
var query = wx.createSelectorQuery();
query.select(’#getHeight’).boundingClientRect()
query.exec(function (resu) {
var res = wx.getSystemInfoSync();
var height = resu[0].height; //这个便是页面的可用高度
var _height = ‘’;
var width = resu[0].width;
if (res.system.indexOf(“iOS”) > -1) {
_height = height - 120;
} else {
_height = height - 70;
}
self.setData({ “windowHight”: _height + “px”, height: _height })
})
}
function getSystemInfo(that, data) { var query = wx.createSelectorQuery() query.select( '.head' ).boundingClientRect() query.exec( function (res) { windowHeight = Math.round(res[0].height) console.log(windowHeight); let a = data_processing(data) //为了上下都有能滑动,所以扔进去三个时间 display_data.push(mydate[0]) display_data.push(mydate[0]) display_data.push(mydate[0]) that.setData({ data: a, display_data: display_data }) console.log( 'display_data' , display_data) console.log( 'mydate' , mydate) }) } |
实际高度46.25,代码返回51.