You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
648 B

/**
* 像素工具
*/
class PixelUtil {
/**
* 构造函数
* @param systemInfo 设备信息
*/
constructor(systemInfo) {
this.systemInfo = systemInfo;
}
/**
* px 转 rpx
* @param pxNumber px数值
* @returns {number} rpx数值
*/
px2rpx(pxNumber) {
return (750 / this.systemInfo.screenWidth) * pxNumber;
}
/**
* rpx 转 px
* @param rpxNumber rpx数值
* @returns {number} px数值
*/
rpx2px(rpxNumber){
return (rpxNumber / 750) * this.systemInfo.screenWidth;
}
}
const pixelUtil = new PixelUtil(wx.getSystemInfoSync());
export default pixelUtil;