orientation.js 
处理重力感应,通过监听 deviceorientation
和 orientationchange
事件。
- 对
deviceorientation
的回调函数参数 DeviceOrientationEvent
进行封装,增加了一些更便于使用的属性, - 统一了
iOS
和 Android
的差异 - 处理了横屏竖屏的情况
DEMO
安装
npm install --save orientation.js
使用
支持 AMD、CMD 或者直接引入。
var Orientation = require('orientation.js')
var ori = new Orientation({
initForwardSlant: 45, // 可选,初始向前倾斜度
onChange: function (e) {
console.log(e)
}
})
ori.init()
介绍
配置项
实例方法
init
初始化,开始监听事件
pause
不触发 onChange
continue
解除 pause
状态
destory
销毁监听事件
启示
感谢 @shrekshrek 的 https://github.com/shrekshrek/orienter
许可
MIT