1、需要借助的API:wx.getSystemInfoSync();
通過API可獲取的值:
// 在 iPhone6 下運(yùn)行:
var systemInfo = wx.getSystemInfoSync();
console.log(systemInfo.windowWidth); // 輸出 375(單位 px)
// 在 iPhone6 Plus 下:
var systemInfo = wx.getSystemInfoSync();
console.log(systemInfo.windowWidth); // 輸出 414 (單位 px)
2、px與rpx之間轉(zhuǎn)換的公式:px = rpx / 750 * wx.getSystemInfoSync().windowWidth;
動(dòng)畫中如何使用:
//假設(shè)我想向右平移300rpx,動(dòng)畫代碼如下:
this.animation.translateX(300 / 750 * systemInfo.windowWidth).step()
這樣在所有機(jī)型上都可以進(jìn)行適配。