-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path移动端拖拽.html
172 lines (145 loc) · 4.61 KB
/
移动端拖拽.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
let path = [];
let result = [];
// function res() {
// add(path, result)
// console.log(result);
// }
function add(path, result) {
result.push(path)
}
add(path, result)
console.log(path);
console.log(result);
var v1 = []
var v2 = {};
var v3 = {};
function foo(v1, v2, v3) {
v1 = [1];
v2 = [2];
v3 = {
a: 3
}
}
foo(v1, v2, v3);
console.log(v1); // 空白
console.log(v2); // [object Object]
console.log(v3.a); // undefined
</script>
<style>
html,
body {
margin: 0;
padding: 0;
}
.ProgressBarWrapper {
height: 30px;
}
.ProgressBarWrapper .bar-inner {
position: relative;
top: 13px;
height: 4px;
background: rgba(0, 0, 0, 0.3);
}
.bar-inner .progress {
position: absolute;
height: 100%;
background: #d44439;
/* width: 200px; */
}
.ProgressBarWrapper .bar-inner .progress-btn-wrapper {
position: absolute;
left: -10px;
top: -13px;
width: 30px;
height: 30px;
/* transform: translate3d(200px, 0px, 0px); */
}
.progress-btn {
position: relative;
top: 7px;
left: 7px;
-webkit-box-sizing: border-box;
box-sizing: border-box;
width: 16px;
height: 16px;
border: 3px solid #e4e4e4;
border-radius: 50%;
background: #d44439;
}
</style>
</head>
<body>
<div class="ProgressBarWrapper">
<div class="bar-inner" id="progressBar">
<div class="progress" id="progress"></div>
<div class="progress-btn-wrapper" id="progressBtn">
<div class="progress-btn"></div>
</div>
</div>
</div>
<button id="button">点击</button>
<script>
let progressBtn = document.getElementById("progressBtn"),
progress = document.getElementById("progress"),
progressBar = document.getElementById("progressBar"),
progressBtnWidth = 20;
let startX = 0;
let left = 0;
let initiated = false;
function progressTouchStart(e) {
startX = e.touches[0].pageX; // 滑动开始时横向坐标
left = progress.clientWidth; // 当前 progress 长度
initiated = true;
}
function progressTouchMove(e) {
if (!initiated) return;
const deltaX = e.touches[0].pageX - startX;
const barWidth = progressBar.clientWidth - progressBtnWidth;
console.log(barWidth);
// const offsetWidth = Math.max(0, this.touch.left + deltaX);
let offsetWidth = Math.min(
barWidth,
Math.max(0, left + deltaX)
)
progress.style.width = `${offsetWidth}px`
progressBtn.style.transform = `translate3d(${offsetWidth}px, 0, 0)`;
}
function progressTouchEnd(e) {
initiated = false
}
function progressClick(e) {
const rect = progressBar.getBoundingClientRect();
// const rect = progressBar.getClientRects();
const offsetWidth = e.pageX - rect.left;
progress.style.width = `${offsetWidth}px`
progressBtn.style.transform = `translate3d(${offsetWidth}px, 0, 0)`;
}
progressBtn.addEventListener("touchstart", progressTouchStart)
progressBtn.addEventListener("touchmove", progressTouchMove)
progressBtn.addEventListener("touchend", progressTouchEnd)
progressBar.addEventListener("click", progressClick)
let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]
function randomArr(arr) {
let m = arr.length;
let new_arr = [...arr]
for (let i = 0; i < m; i++) {
let j = Math.floor(Math.random() * i);
let t = new_arr[i];
new_arr[i] = new_arr[j];
new_arr[j] = t;
}
console.log(new_arr);
}
button.addEventListener("click", () => {
randomArr(arr)
})
</script>
</body>
</html>