小程序,刘海屏iPhoneX等样式兼容问题

//在app.js内的onShow内加上这一段代码

let that = this;
	wx.getSystemInfo({
	success: res => {
		that .globalData.headerBtnPosi = wx.getMenuButtonBoundingClientRect().top
		let modelmes = res.model;
		if (modelmes.search('iPhone X') != -1 || modelmes.search('iPhone 11') != -1) {
			that.globalData.isIphoneX = true
		}

	}
})

然后在样式兼容有问题的页面内onload内获取一下当前手机的系统信息

//onload
let isIphoneX = app.globalData.isIphoneX;
this.setData({
	isIphoneX:isIphoneX
})

单独写出样式需要修改的样式,判断添加

	<view class="loadgif {{isIphoneX?'isIPX':''}}">123</view>

你可能感兴趣的:(前端)