注:#getheight为view绑定的id命名
// 获取view的高度
windowWidth: ‘’,
scroll_height: ‘’,
// 获取系统宽度
getSystemInfo: function() {
let that = this
wx.getSystemInfo({
success: function(res) {
console.log(‘res.windowWidth’, res.windowWidth)
that.setData({
windowWidth: res.windowWidth
})
}
})
},
// 获取view的高度
view_height: function() {
let that = this
that.getSystemInfo()
var query = wx.createSelectorQuery();
query.select(’#getheight’).boundingClientRect() //获取view的id
query.exec(function(res) {
let viewheight = (res[0].height * (750 / (that.data.windowWidth))) //px转换为rpx(view的高度*750/当前手机的宽度)
console.log(viewheight, ‘viewheight’)
that.setData({
scroll_height: viewheight
})
})
},
小程序定位引起view高度不能由内容撑开的问题?
最新推荐文章于 2022-05-27 11:29:38 发布