-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathd.html
92 lines (75 loc) · 2.68 KB
/
d.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<html>
<head>
<title>DeviceOrientationEvent</title>
<meta charset="UTF-8" />
</head>
<body>
<p>左右:<span id="alpha">0</span>
</p>
<p>前后:<span id="beta">0</span>
</p>
<p>扭转:<span id="gamma">0</span>
</p>
<p>指北针指向:<span id="heading">0</span>度</p>
<p>指北针精度:<span id="accuracy">0</span>度</p>
<hr />
<p>x轴加速度:<span id="x">0</span>米每二次方秒</p>
<p>y轴加速度:<span id="y">0</span>米每二次方秒</p>
<p>z轴加速度:<span id="z">0</span>米每二次方秒</p>
<hr />
<p>x轴加速度(考虑重力加速度):<span id="xg">0</span>米每二次方秒</p>
<p>y轴加速度(考虑重力加速度):<span id="yg">0</span>米每二次方秒</p>
<p>z轴加速度(考虑重力加速度):<span id="zg">0</span>米每二次方秒</p>
<hr />
<p>左右旋转速度:<span id="Ralpha">0</span>度每秒</p>
<p>前后旋转速度:<span id="Rbeta">0</span>度每秒</p>
<p>扭转速度:<span id="Rgamma">0</span>度每秒</p>
<hr />
<p>上次收到通知的间隔:<span id="interval">0</span>毫秒</p>
<script type="text/javascript">
function orientationHandler(event) {
document.getElementById("alpha").innerHTML = event.alpha;
document.getElementById("beta").innerHTML = event.beta;
document.getElementById("gamma").innerHTML = event.gamma;
document.getElementById("heading").innerHTML = event.webkitCompassHeading;
document.getElementById("accuracy").innerHTML = event.webkitCompassAccuracy;
}
var oldAcc = {};
var oldAccGravity = {};
function motionHandler(event) {
document.getElementById("interval").innerHTML = event.interval;
var acc = event.acceleration;
// for(var key in acc) {
// if (oldAcc[key]) {
// document.getElementById(key).innerHTML = (acc[key] * 10).toFixed(1);
// }
// }
var accGravity = event.accelerationIncludingGravity;
var maxAcc = 0, maxKey = 'x', str = "";
for (var key in accGravity) {
if (Math.abs(accGravity[key]) > maxAcc) {
maxAcc = Math.abs(accGravity[key]);
maxKey = key;
}
str += key + ":" + Math.abs(accGravity[key]) + " ";
}
var error = accGravity[maxKey] + 9.81;
document.getElementById('x').innerHTML = accGravity['x'];
document.getElementById('y').innerHTML = accGravity['y'];
document.getElementById('z').innerHTML = accGravity['z'];
// window.removeEventListener("devicemotion", motionHandler, false);
//return;
}
if (window.DeviceMotionEvent) {
window.addEventListener("devicemotion", motionHandler, false);
} else {
document.body.innerHTML = "What user agent u r using???";
}
if (window.DeviceOrientationEvent) {
//window.addEventListener("deviceorientation", orientationHandler, false);
} else {
document.body.innerHTML = "What user agent u r using???";
};
</script>
</body>
</html>