方式一:getSystemInfo:需要在success方法中取值
wx.getSystemInfo({
success:function(res) {
console.log(res.windowWidth, '宽')
console.log(res.windowHeight, '长')
}
})
方式二:getSystemInfoSync:可以直接".windowWidth"取值
console.log(wx.getSystemInfoSync().windowWidth, '宽')
console.log(wx.getSystemInfoSync().windowHeight, '长')
1、官方上规定屏幕宽度为20rem,规定屏幕宽为750rpx,则1rem=750/20rpx。
即:不论哪个型号的手机,屏幕宽度都是750rpx
2、微信小程序rpx,px,rem单位换算规则
屏幕实际宽度为:wx.getSystemInfoSync().windowWidth px
对应的屏幕宽度为:750rpx
即:1px = (750 / wx.getSystemInfoSync().windowWidth) rpx
1rpx = (wx.getSystemInfoSync().windowWidth / 750) px文章来源:https://www.toymoban.com/news/detail-518464.html
1rem = (wx.getSystemInfoSync().windowWidth / 20) px
文章来源地址https://www.toymoban.com/news/detail-518464.html
到了这里,关于小程序获取屏幕宽高wx.getSystemInfoSync().windowWidth的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!