-
Notifications
You must be signed in to change notification settings - Fork 1
/
gyroscope.js
37 lines (28 loc) · 1.08 KB
/
gyroscope.js
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
(function() {
var element = document.getElementById('gyroscope');
var compass = document.getElementById('compass');
compass.hidden = true;
function handleOrientation(event) {
var absolute = event.absolute;
var alpha = event.alpha;
var beta = event.beta;
var gamma = event.gamma;
element.innerHTML = 'Orientation: ' + absolute
if (!alpha) {
compass.hidden = true;
element.innerHTML += '<br>Your device has no compass ';
} else {
compass.hidden = false;
element.innerHTML += '<br>alpha: ' + alpha
}
element.innerHTML += '<br>beta: ' + beta
element.innerHTML += '<br>gamma: ' + gamma + '<br>'
// Do stuff with the new orientation data
if (Math.abs(beta) + Math.abs(gamma) < 1.8) {
element.innerHTML += 'Your Device is probably laying on a Table';
} else {
element.innerHTML += 'Your Device is probably in your Hands';
}
}
window.addEventListener('deviceorientation', handleOrientation);
}());