大宁摇一摇
2015-08-10 18:24
239 查看
1.H5摇一摇事件 window.DeviceMotionEvent
var SHAKE_THRESHOLD = 3000; var last_update = 0; var x = y = z = last_x = last_y = last_z = 0; if (window.DeviceMotionEvent) { window.addEventListener('devicemotion', deviceMotionHandler, false); } else { alert('not support mobile event'); } function deviceMotionHandler(eventData) { var acceleration = eventData.accelerationIncludingGravity; var curTime = new Date().getTime(); if ((curTime - last_update) > 100) { var diffTime = curTime - last_update; last_update = curTime; x = acceleration.x; y = acceleration.y; z = acceleration.z; var speed = Math.abs(x + y + z - last_x - last_y - last_z) / diffTime * 10000; if (speed > SHAKE_THRESHOLD) { //摇一摇需要做的事情 } last_x = x; last_y = y; last_z = z; } }
相关文章推荐
- 有100个节点的AVL树最大深度是多少?
- VFL示例
- HDU 1069 Monkey and Banana
- 线段树模版(转)
- POJ 3468 A Simple Problem with Integers (线段树,成段更新,区间求和)
- 关于jqGrid动态改变列的解决方案
- php5.3以上服务器单独安装php不安装mysql
- java 利用org.apache.poi.hssf包编写excel导出文件
- python 常用string函数
- (4.2.19)彩色进度条CircleProgress, DonutProgress, ArcProgress
- wcf生成代理类(SVCUtil.exe的用法)
- Android之Service例程
- json日期格式话
- Android基础:广播接收器及其生命周期介绍
- HDU3681Prison Break(BFS+TSP+二分+dp状态压缩)
- C语言-06-复杂数据类型
- 笔试测试题
- 线段树之HDU4614 Vases and Flowers
- 区间最小值(2) (线段树 更新区间)2015年 JXNU_ACS 算法组暑假第一次周赛
- 并查集的详解与应用(基础篇)