小程序获取px后转为rpx

获取设备信息时得到的窗口高度宽度是px为单位的。  在实际使用时,一般使用rpx ,中间要有个转换过程.

豌豆资源搜索网站https://55wd.com 电脑刺绣绣花厂 ttp://www.szhdn.com

代码如下:

wx.getSystemInfo({
  success:function (res) {
    console.log(res.windowHeight) // 获取可使用窗口高度
    let windowHeight = (res.windowHeight * (750 / res.windowWidth)); 
    console.log(windowHeight) //获得rpx单位的窗口高度
  }
}) 
posted @ 2020-09-22 15:00  酷儿q  阅读(899)  评论(0编辑  收藏  举报