-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
72 lines (62 loc) · 1.59 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>
Mobile-test
</title>
<style>
.square
{
width: 100%;
height: 20vh;
margin-top: 20px;
background: red;
}
</style>
</head>
<body>
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<div class="contianer">
<div class="square"></div>
<div class="square"></div>
<div class="square"></div>
<div class="square"></div>
</div>
y: <div class="y"></div>
x: <div class="x"></div>
z: <div class="z"></div>
<script>
data_x = 0;
data_y = 0;
data_z = 0;
$(document).ready(function()
{
window.addEventListener("devicemotion",onDeviceMotion,false);
function loop()
{
console.log(data_x +' '+data_y+' '+ data_z);
$.ajax({
url: '/',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify({x:data_x,y:data_y,z:data_z})}
);
setTimeout(function()
{
loop();
}, 300);
}
});
function onDeviceMotion()
{
data_x = Math.round(event.accelerationIncludingGravity.x);
data_y = Math.round(event.accelerationIncludingGravity.y);
data_z = Math.round(event.accelerationIncludingGravity.z);
$('.x').html(data_x);
$('.y').html(data_y);
$('.z').html(data_z);
}
</script>
</body>
</html>