-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathandy.html
97 lines (86 loc) · 3.17 KB
/
andy.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
97
<html>
<head>
<title>Game Controller</title>
<!-- Include jQuery -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script>
$(document).ready(function() {
if (window.DeviceOrientationEvent) {
$("body").css("background-color","#00FF00");
$("#doEvent").text("DeviceOrientationEvent");
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) {
$("body").css("background-color","#00FF00");
$("#doEvent").text("OrientationEvent");
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 {
$("body").css("background-color","#FF0000");
}
function deviceOrientationHandler(tiltLR, tiltFB, dir, motUD) {
console.log("handler");
$("#doTiltLR").text(Math.round(tiltLR));
$("#doTiltFB").text(Math.round(tiltFB));
$("#doDirection").text(Math.round(dir));
$("#doMotionUD").text(motUD);
// 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>
</head>
<body>
<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>
</body>
</html>