1、需要借助的API:wx.getSystemInfoSync();

通过API可获取的值:

1 // 在 iPhone6 下运行:
2 var systemInfo = wx.getSystemInfoSync();
3 console.log(systemInfo.windowWidth); // 输出 375(单位 px)
4 // 在 iPhone6 Plus 下:
5 var systemInfo = wx.getSystemInfoSync();
6 console.log(systemInfo.windowWidth); // 输出 414 (单位 px)

2、px与rpx之间转换的公式:px = rpx / 750 * wx.getSystemInfoSync().windowWidth;

1 // 假设设计图中按钮向右偏移了300rpx,动画代码如下:
2 this.animation.translateX(300 / 750 * systemInfo.windowWidth).step()

这样在所有机型上都可以进行适配。

相关文章:

  • 2021-06-30
  • 2021-09-19
  • 2022-12-23
  • 2021-09-10
  • 2021-05-21
  • 2022-12-23
  • 2021-08-23
猜你喜欢
  • 2022-03-07
  • 2021-07-17
  • 2022-12-23
  • 2022-01-06
  • 2022-12-23
相关资源
相似解决方案