单位转换问题?
发布于 7 年前 作者 xcheng 9692 次浏览 来自 官方Issues

https://developers.weixin.qq.com/miniprogram/dev/framework/view/selector.html

这里获取到的数值单位是什么?

怎么转换成rpx?

5 回复

var res = wx.getSystemInfoSync().windowWidth;

var scale = (750 / 2) / (w / 2);

//以宽度750px设计稿做宽度的自适应

real = Math.floor(res / scale);

getSystemInfo 拿到 windowWidth

这个windowWidth单位是px

而对应的屏幕宽度是 750rpx

wx.getSystemInfo({

  success:function (res) {

    console.log(res.windowHeight) // 获取可使用窗口高度

    let windowHeight = (res.windowHeight * (750 / res.windowWidth)); //将高度乘以换算后的该设备的rpx与px的比例

    console.log(windowHeight) //最后获得转化后得rpx单位的窗口高度

  }

})

获取的单位好像都是px

res里的应该是px

回到顶部