您的位置:宽带测速网 > 网络知识 > 如何动态获取小程序页面的高度

如何动态获取小程序页面的高度

2025-06-17 10:01来源:互联网 [ ]

使用onReady事件动态获取小程序页面的高度

实现代码如下:

onReady:function(){

//动态获取高度

this.autoHeight();

},

//动态获取高度

autoHeight:function(){

varthat=this;

varquery=wx.createSelectorQuery();

query.select('.container').boundingClientRect(function(rect){

console.log("----w"+rect.height)

that.setData({

windowHeight:rect.height,//获取页面高度

})

}).exec();

},