- orientationchange(翻转屏幕时触发)
- window.orientation:0-竖屏 90-右旋转 -90-左旋转
- 获取屏幕横竖屏状态
- deviceorientation + devicemotion(重力感应与陀螺仪) MDN文档
-
deviceorientation-处理方向事件(移动的角度)
-
DeviceOrientationEvent.alpha 表示设备沿z轴上的旋转角度,范围为0~360。
-
DeviceOrientationEvent.beta 表示设备在x轴上的旋转角度,范围为-180~180。它描述的是设备由前向后旋转的情况。
-
DeviceOrientationEvent.gamma 表示设备在y轴上的旋转角度,范围为-90~90。它描述的是设备由左向右旋转的情况。
window.addEventListener('deviceorientation', function(e){ console.log('absolute: ' + e.absolute) console.log('alpha: ' + e.alpha) console.log('beta: ' + e.beta) console.log('gamma: ' + e.gamma) });
-
-
devicemotion-监听加速度的变化
- DeviceMotionEvent.acceleration
- x: 西向东
- y: 南向北
- z: 垂直地面
- DeviceMotionEvent.accelerationIncludingGravity
- x: 西向东
- y: 南向北
- z: 垂直地面
- DeviceMotionEvent.rotationRate
- alpha: 设备沿着垂直屏幕的轴的旋转速率 (桌面设备相对于键盘)
- beta: 设备沿着屏幕左至右方向的轴的旋转速率(桌面设备相对于键盘)
- gamma: 设备沿着屏幕下至上方向的轴的旋转速率(桌面设备相对于键盘)
- DeviceMotionEvent.interval
- 从设备获取数据的频率,单位是毫秒。
- DeviceMotionEvent.acceleration
-
- console--More tools--Sensors
- threejs中的方法
var quaternion = new THREE.Quaternion();
quaternion.setFromAxisAngle( new THREE.Vector3( 0, 1, 0 ), Math.PI / 2 );
var vector = new THREE.Vector3( 1, 0, 0 );
vector.applyQuaternion( quaternion );