-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.html
69 lines (62 loc) · 2.04 KB
/
test.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>This web has been backed.</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style lang="css">
* {
margin: 0;
padding: 0;
}
html,
body {
height: 100vh;
width: 100%;
}
body {
position: relative;
}
canvas {
display: block;
z-index: -1;
position: absolute;
top: 0;
left: 0;
}
</style>
</head>
<body>
<canvas id="canvas"></canvas>
<script>
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
var string1 = "01";
string1.split("");
var fontsize = 20;
columns = canvas.width / fontsize;
var drop = [];
for (var x = 0; x < columns; x++) {
drop[x] = 0;
}
function drap() {
ctx.fillStyle = "rgba(0,0,0,0.07)";
ctx.fillRect(0, 0, canvas.width, canvas.height); //fillRect(x,y,width,height),x坐标、y坐标、width宽、height高
ctx.fillStyle = "#0F0";
ctx.font = fontsize + "px arial";
for (var i = 0; i < drop.length; i++) {
var text1 = string1[Math.floor(Math.random() * string1.length)];
ctx.fillText(text1, i * fontsize, drop[i] * fontsize); //fillText(text,x,y,maxWidth),text画布文本、开始绘制文本的 x 坐标位置、开始绘制文本的 y 坐标位置、可选。允许的最大文本宽度,以像素计
drop[i]++;
if (drop[i] * fontsize > canvas.height && Math.random() > 0.9) { //90%的几率掉落
drop[i] = 0;
}
}
}
setInterval(drap, 20);
</script>
</body>
</html>