px和rpx换算
rpx是小程序中的尺寸单位,它有以下特征:
小程序的屏幕宽固定为750rpx(即750个物理像素),在所有设备上都是如此。
1rpx=(screenWidth / 750)px,其中screenWidth为手机屏幕的实际的宽度(单位px)。
举例子:
可获得在当前设备下的屏幕中,rpx所换算的px值
1rpx=res.screenWidth/750
var bgheight = res.windowHeight/rate-20,bgheight为对话框区域scroll-view的高度,减去的20是输入对话的文本框的长度
wx.getSystemInfo({
success: function (res) {
console.log(res.screenWidth)
console.log("1rpx="+res.screenWidth/750)
console.log(res.windowHeight)
console.log(res.screenHeight)
console.log(res.statusBarHeight)
var rate=res.screenWidth/750
var bgheight = res.windowHeight/rate-20
console.log(bgheight)
that.setData({
bgheight: bgheight
})
}
})