借助API

wx.getSystemInfoSync();
通过API可获取的值:


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

px与rpx之间转换的公式

var px = rpx / 750 * wx.getSystemInfoSync().windowWidth;

动画中如何使用:

//假设我想向右平移300rpx,动画代码如下:
this.animation.translateX(300 / 750 * systemInfo.windowWidth).step()

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

相关文章:

  • 2021-05-21
  • 2022-12-23
  • 2022-01-10
  • 2022-12-23
  • 2021-12-02
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-10
  • 2021-07-17
  • 2022-12-23
  • 2021-08-23
  • 2021-07-24
相关资源
相似解决方案