-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrain.html
58 lines (57 loc) · 1.3 KB
/
rain.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<style type="text/css">
*{
padding: 0;
margin: 0;
}
html,body{
width: 100%;
height: 100%;
background: black;
overflow: hidden;
}
.rain{
width: 2px;
height: 10px;
background: #fff;
filter: blur(1px);
position: absolute;
left: 0;
top: 0;
transition: all ease 1s;
}
</style>
<body>
</body>
</html>
<script type="text/javascript">
for(let i=0;i<200;i++){
let div=document.createElement('div');
div.classList.add('rain');
document.body.appendChild(div);
let lefts=(window.innerWidth-200)*Math.random()+100;
let tops=Math.random()*50;
div.style.left=`${lefts}px`;
div.style.top=`${tops}px`;
}
document.body.onclick=function(){
let rain=document.querySelectorAll('div');
rain.forEach((element)=>{
element.style.transition=`all ease 1s ${Math.random()}s`;
element.style.top=`${window.innerHeight+50}px`;
element.addEventListener('webkitTransitionEnd',function(){
element.style.transition='none';
element.style.top='-50px';
setTimeout(function(){
element.style.transition=`all ease 1s ${Math.random()}s`;
element.style.top=`${window.innerHeight+50}px`;
},1000)
})
})
}
</script>