-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
81 lines (66 loc) · 2.61 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<title>Rotation Api</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
<script src="js/rotate.js"></script>
<link rel="stylesheet" type="text/css" href="style/style.css">
</head>
<body>
<div id="rotation_indicator_back"></div>
<div id="rotation_indicator"></div>
<div id="degrees" class="label"></div>
<div id="x" class="label"></div>
<div id="y" class="label"></div>
<div id="z" class="label"></div>
</body>
<script type="text/javascript">
var visibilityEvent = 'visibilitychange';
var hiddenProperty = 'hidden';
if (typeof(document.webkitHidden) !== 'undefined') {
visibilityEvent = 'webkitvisibilitychange';
hiddenProperty = 'webkitHidden';
} else if (typeof(document.mozHidden) !== 'undefined') {
visibilityEvent = 'mozvisibilitychange';
hiddenProperty = 'mozHidden';
}
var myRotateEvent = null;
var rotateOptions = { invert: true } // invert all angles to compensate for device orientation
var rotationIndicator = document.getElementById('rotation_indicator');
var rotationIndicatorBack = document.getElementById('rotation_indicator_back');
var degLabel = document.getElementById('degrees');
var xLabel = document.getElementById('x');
var yLabel = document.getElementById('y');
var zLabel = document.getElementById('z');
function displayRotation(event) {
var rotXCss = 'rotatex('+ (event.rotation.x) +'deg)';
var rotYCss = 'rotatey('+ (event.rotation.y) +'deg)';
var rotZCss = 'rotatez('+ (event.rotation.z) +'deg)';
degLabel.innerHTML = 'Window-Orientation: ' + event.orientation;
xLabel.innerHTML = 'X: ' + Math.round(event.rotation.x);
yLabel.innerHTML = 'Y: ' + Math.round(event.rotation.y);
zLabel.innerHTML = 'Z: ' + Math.round(event.rotation.z);
rotationIndicator.style.webkitTransform = rotXCss + ' ' + rotYCss + ' ' + rotZCss;
rotationIndicatorBack.style.webkitTransform = rotXCss + ' ' + rotYCss + ' ' + rotZCss;
rotationIndicator.style.transform = rotXCss + ' ' + rotYCss + ' ' + rotZCss;
rotationIndicatorBack.style.transform = rotXCss + ' ' + rotYCss + ' ' + rotZCss;
}
/* Disable listeners for device rotation when the window
or tab is not visible to save power. */
function handleVisibilityChange(event) {
if (document[hiddenProperty]) {
myRotateEvent.stop();
} else {
myRotateEvent.start(rotateOptions);
}
}
function init() {
//create a new instance of rotate.js.
var myRotateEvent = new Rotate();
window.addEventListener('rotate', displayRotation);
myRotateEvent.start(rotateOptions);
document.addEventListener(visibilityEvent, handleVisibilityChange, false);
}
window.onload = init;
</script>
</html>