小程序中物理像素逻辑橡素的转换

41 阅读1分钟

使用 wx.getSystemInfo 获取设备信息

    wx.getSystemInfo({
        sucess(res){
            // 获取屏幕宽度
            let windowWidth = res.windowWidth;
            
            // 逻辑像素转物理像素
            let rpx = 200;
            let px = rpx * windowWidth / 750;
            
            // 物理像素转逻辑像素
            let px2 = 15;
            let rpx2 = px2 / 750 * windowWidth;
        }
    })