-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
118 lines (105 loc) · 3.16 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<!DOCTYPE html>
<html lang="en">
<head>
<style>
body {
margin: 0px;
padding: 0px;
overflow: hidden;
}
#test {
position: absolute;
left: 15%;
top: 80%;
transform: translate(-50%, -50%);
background-color: rgb(100, 100, 100);
width: 80px;
height: 80px;
}
#text {
padding: 10px;
-webkit-user-select: none;
-moz-user-select: none;
-o-user-select: none;
user-select: none;
background: #eee;
}
.div1 {
width: 200px;
height: 200px;
background: rgba(0, 0, 0, 0.15);
border-radius: 100%;
position: absolute;
top: 80%;
left: 50%;
margin-left: -100px;
margin-top: -100PX;
}
.div2 {
width: 50px;
height: 50px;
background: rgb(255, 255, 255);
border-radius: 100%;
position: absolute;
top: 80%;
left: 50%;
margin-left: -25px;
margin-top: -25px;
}
.div3 {
width: 200px;
height: 200px;
border-radius: 100%;
position: absolute;
top: 80%;
left: 50%;
margin-left: -100px;
margin-top: -100PX;
}
</style>
<meta charset="UTF-8">
<meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" name="viewport" />
<title>3D景区云游</title>
<script type="module" src="script.js"></script>
</head>
<body>
<div id="test">
<div id="text" align="center">
<h5>跳跃</h5>
</div>
</div>
<div id="container"></div>
<div class="div1"></div>
<div class="div2"></div>
<div class="div3"></div>
<script>
window.rad = 0;
window.d = 0;
let div3 = document.querySelector('.div3')
let div2 = document.querySelector('.div2')
let r = 25 //摇杆的半径
let r2 = 100 //底盘的半径
let x = div2.offsetLeft + r //加上r半径的偏移到中心
let y = div2.offsetTop + r
div3.ontouchmove = (e) => {
let t = e.changedTouches[0]
//开根 触摸点到摇杆中心点的距离
let d = Math.sqrt(Math.pow(t.pageX - x, 2) + Math.pow(t.pageY - y, 2))
d = d > (r2 - r) ? r2 - r : d
//三角函数求反正切 减去xy偏移到中心点
let radin = Math.atan2(t.pageY - y, t.pageX - x)
let vx = x + Math.cos(radin) * d
let vy = y + Math.sin(radin) * d
div2.style.left = vx + 'px'
div2.style.top = vy + 'px'
window.rad = radin;
window.d = d;
}
div3.ontouchend = () => {
div2.style.left = x + 'px'
div2.style.top = y + 'px'
window.d = 0;
}
</script>
</body>
</html>