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

1369
2020/12/11 15:00:08
栏目: 云计算
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

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

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

实现代码如下:

onReady: function () {

//动态获取高度

this.autoHeight();

},

//动态获取高度

autoHeight:function(){

var that = this;

var query = wx.createSelectorQuery();

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

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

that.setData({

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

})

}).exec();

},

辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: 小程序代码由什么页面组成