微信小程序中获取页面的实际宽高和rpx的关系getSystemInfoSync

小程序提供了一个方法叫getSystemInfoSync,通过它可以获取当前屏幕信息

const info = wx.getSystemInfoSync();
const 与rpx的比值 = 750 / systemInfo.windowWidth;
const 屏幕宽度 = info.screenWidth;
const 屏幕高度 = info.screenHeight;
const 状态栏高度 = info.statusBarHeight;
const 可用窗口宽度 = info.windowWidth;
const 可用窗口高度 = info.windowHeight;

上面获取的是px为单位的,要是需要设置当前元素的值,需要转换成rxp
如我想要获取当前可用窗口的rpx高度:

实际rpx高度 = 与荣幸的比值 * 可用窗口的高度;
rpxHeight = 750 / systemInfo.windowWidth * info.windowHeight;

猜你喜欢

转载自blog.csdn.net/sunyv1/article/details/107762071