-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathsnow.html
More file actions
86 lines (72 loc) · 2.22 KB
/
snow.html
File metadata and controls
86 lines (72 loc) · 2.22 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
80
81
82
83
84
85
86
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Snow</title>
<style>
body {
background-color: black;
overflow: hidden;
height: 100vh;
cursor: pointer;
}
.ts {
transition-property: all;
transition-timing-function: ease;
}
img {
height: 15px;
position: absolute;
top: 0;
left: 50vw;
transform: translate(-50%);
}
</style>
</head>
<body>
</body>
<script>
var animating = false;
var created = false;
function createSnows() {
if (created) {
return
}
for (var i = 0; i < 800; i++) {
var img = document.createElement("img");
img.src = "./snow.png";
img.className = "ts";
var w = (10 + Math.round(Math.random() * 30)) + "px";
img.style.width = w;
img.style.height = w;
document.body.appendChild(img)
}
created = true;
}
function updateSnows() {
[...document.images].forEach(function (el, i) {
el.classList.add("ts");
el.style.transitionDuration = 3000 + Math.floor(Math.random() * i * 1000/800 ) + "ms";
el.style.left = 50 + (Math.random() > 0.49 ? 1 : -1) * Math.random() * 200 + "vw";
el.style.top = 100 + 1 * Math.round(Math.random() * 50) + "vh";
el.style.transitionTimingFunction = `cubic-bezier(${Math.random().toFixed(2)},${Math.random().toFixed(2)},${Math.random().toFixed(2)},${Math.random().toFixed(2)})`
})
}
function resetSnows() {
[...document.images].forEach(function (el, i) {
el.style.transition = "";
el.style.top = "0";
el.style.left = "50vw";
el.classList.remove("ts");
})
}
createSnows();
document.body.addEventListener("click", function () {
resetSnows();
window.getComputedStyle(document.body);
requestAnimationFrame(updateSnows)
})
</script>
</html>