forked from kevbaldwyn/weatherama
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tomg_test.html
executable file
·96 lines (83 loc) · 3.33 KB
/
tomg_test.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
93
94
95
96
<html>
<script type="text/javascript">
if (window.DeviceOrientationEvent) {
// Listen for the deviceorientation event and handle DeviceOrientationEvent object
window.addEventListener('deviceorientation', devOrientHandler, false);
} else if (window.OrientationEvent) {
// Listen for the MozOrientation event and handle OrientationData object
window.addEventListener('MozOrientation', mozDevOrientHandler, false);
}
if (window.DeviceOrientationEvent) {
document.getElementById("doEvent").innerHTML = "DeviceOrientation";
// Listen for the deviceorientation event and handle the raw data
window.addEventListener('deviceorientation', function(eventData) {
// gamma is the left-to-right tilt in degrees, where right is positive
var tiltLR = eventData.gamma;
// beta is the front-to-back tilt in degrees, where front is positive
var tiltFB = eventData.beta;
// alpha is the compass direction the device is facing in degrees
var dir = eventData.alpha
// deviceorientation does not provide this data
var motUD = null;
// call our orientation event handler
deviceOrientationHandler(tiltLR, tiltFB, dir, motUD);
}, false);
} else if (window.OrientationEvent) {
document.getElementById("doEvent").innerHTML = "MozOrientation";
window.addEventListener('MozOrientation', function(eventData) {
// x is the left-to-right tilt from -1 to +1, so we need to convert to degrees
var tiltLR = eventData.x * 90;
// y is the front-to-back tilt from -1 to +1, so we need to convert to degrees
// We also need to invert the value so tilting the device towards us (forward)
// results in a positive value.
var tiltFB = eventData.y * -90;
// MozOrientation does not provide this data
var dir = null;
// z is the vertical acceleration of the device
var motUD = eventData.z;
// call our orientation event handler
deviceOrientationHandler(tiltLR, tiltFB, dir, motUD);
}, false);
} else {
document.getElementById("doEvent").innerHTML = "Not supported on your device or browser."
}
document.getElementById("doTiltLR").innerHTML = Math.round(tiltLR);
document.getElementById("doTiltFB").innerHTML = Math.round(tiltFB);
document.getElementById("doDirection").innerHTML = Math.round(dir);
document.getElementById("doMotionUD").innerHTML = motionUD;
// Apply the transform to the image
document.getElementById("imgLogo").style.webkitTransform = "rotate(" +
tiltLR + "deg) rotate3d(1,0,0, " + (tiltFB * -1) + "deg)";
document.getElementById("imgLogo").style.MozTransform = "rotate(" + tiltLR + "deg)";
document.getElementById("imgLogo").style.transform = "rotate(" + tiltLR +
"deg) rotate3d(1,0,0, " + (tiltFB * -1) + "deg)";
</script>
<div class="main">
<h2>Device Orientation</h2>
<table>
<tr>
<td>Event Supported</td>
<td id="doEvent"></td>
</tr>
<tr>
<td>Tilt Left/Right [tiltLR]</td>
<td id="doTiltLR"></td>
</tr>
<tr>
<td>Tilt Front/Back [tiltFB]</td>
<td id="doTiltFB"></td>
</tr>
<tr>
<td>Direction [direction]</td>
<td id="doDirection"></td>
</tr>
<tr>
<td>Motion Up/Down</td>
<td id="doMotionUD"></td>
</tr>
</table>
</div>
<div class="container" style="-webkit-perspective: 300; perspective: 300;">
<img src="_dev/data-image/2012-09-28T19-00-00.png" id="imgLogo" class="logo">
</div>
</html>