开发微信小程序使用陀螺仪制作重力感应动态卡片【小程序】❄️2winter2021-03-122021-03-12这段代码是去年写项目用到的,从笔记里提出来。 12345678910111213141516let __tksjdkajs = Date.now(); wx.onAccelerometerChange(async function (res) { let deg = 0; let now = Date.now() if (now - __tksjdkajs > 600) { let absX = Math.abs(res.x); let absY = Math.abs(res.y); (absX > 0.1 || absY > 0.1) && (deg = 5); _this.setData({ accelerometer: { ...res, deg } }); __tksjdkajs = now; } }); style="transform: rotate3d({{(accelerometer.y)}},{{-(accelerometer.x)}},{{0}},{{-accelerometer.deg}}deg);"