-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path屏幕测试.html
More file actions
79 lines (66 loc) · 1.95 KB
/
Copy path屏幕测试.html
File metadata and controls
79 lines (66 loc) · 1.95 KB
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>屏幕测试</title>
</head>
<body>
<h1>屏幕测试</h1>
<div id="screen"></div>
<script>
const screen = document.getElementById("screen");
let step = 0;
function goBack() {
if (step > 0) {
step--;
updateScreen();
}
}
function exitTest() {
step = -1;
updateScreen();
}
function updateScreen() {
const colors = ["red", "green", "blue", "yellow", "cyan", "magenta"];
const color = colors[step % colors.length];
if (step === -1) {
screen.style.backgroundColor = "white";
screen.innerHTML = "<h2>测试结束</h2>";
} else {
screen.style.backgroundColor = color;
screen.innerHTML = "<h2>步骤 " + (step + 1) + "</h2>"
}
}
document.addEventListener("keydown", function(event) {
// 监听 ESC 键,退出测试
if (event.key === "Escape") {
exitTest();
}
});
screen.addEventListener("mousedown", function(event) {
// 监听鼠标右键,返回上一步测试
if (event.button === 2) {
goBack();
}
});
screen.addEventListener("touchstart", function(event) {
let touchStartTime = new Date().getTime();
screen.addEventListener("touchend", function(event) {
let touchEndTime = new Date().getTime();
let touchDuration = touchEndTime - touchStartTime;
// 长按触摸屏,返回上一步测试
if (touchDuration >= 1000) {
goBack();
}
}, { once: true });
screen.addEventListener("touchstart", function(event) {
// 双击触摸屏,退出测试
let doubleClickEndTime = new Date().getTime();
if (doubleClickEndTime - touchStartTime <= 300) {
exitTest();
}
}, { once: true });
});
</script>
</body>
</html>