px2rpx单位转换
将px转换成对应的rpx
js
const px2rpx = function (pxNumber) {
const { screenWidth } = wx.getSystemInfoSync();
return (750 / screenWidth) * pxNumber;
};
备注
wx.getSystemInfoSync 获取页面的宽高,通过750/screenWidth(页面的宽度)获取比例,再和px值相乘,就可以得到对应的rpx值