-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJS-snow-1-web.html
54 lines (51 loc) · 1.22 KB
/
JS-snow-1-web.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<style type="text/css">
*{margin: 0;padding: 0;}
body{
background: #000;
width: 100%;
height: 100%;
overflow: hidden;
}
</style>
<body>
<div id="flame">
</div>
</body>
<script type="text/javascript">
//空对象
function Obj() {};
//添加原型方法
Obj.prototype.draw = function(o) {
var speed = 0;
var startLeft = Math.ceil(Math.random() * document.documentElement.clientWidth);
o.style.opacity = (Math.ceil(Math.random() * 5) + 5) / 10; //设置雪花透明度
o.style.left = startLeft + 'px';
o.style.color = '#fff';
o.style.fontSize = 12 + Math.ceil(Math.random() * 14) + 'px';
setInterval(function() {
if (speed < document.documentElement.clientHeight) {
o.style.top = speed + 'px';
o.style.Left = startLeft + Math.ceil(Math.random() * 8) + 'px';
speed += 10;
} else {
o.style.display = 'none';
}
}, 400);
};
var flame = document.getElementById('flame');
setInterval(function() {
var oDiv = document.createElement('div');
oDiv.innerHTML = "*";
oDiv.style.position = 'absolute';
flame.appendChild(oDiv);
var obj = new Obj();
obj.draw(oDiv);
}, 100);
</script>
</html>