px 转化 为 rpx

小程序 的 px 转化为rpx

在 获取 屏幕高度 后 ,这个单位是px ,可是我的项目是用rpx,所以这里就涉及一个转化的公式了

1rpx = 750 / 设备屏幕宽度

所以 

wx.getSystemInfo({
  success:function (res) {
  console.log(res.windowHeight) // 获取可使用窗口高度
  let windowHeight = (res.windowHeight * (750 / res.windowWidth)); //将高度乘以换算后的该设备的rpx与px的比例
  console.log(windowHeight) //最后获得转化后得rpx单位的窗口高度
  }
})

rpx =   px *(750/res.windowWidth)

px = rpx / (750 * wx.getSystemInfoSync().windowWidth)

参考 :https://blog.csdn.net/qq_41080490/article/details/80268298

原文地址:https://www.cnblogs.com/j190512/p/12634551.html