forked from jackfrued/Python-100-Days
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhomework03.html
65 lines (64 loc) · 1.4 KB
/
homework03.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
#container {
width: 800px;
height: 400px;
border: 1px solid black;
margin: 0 auto;
}
#panel {
width: 800px;
margin: 10px auto;
text-align: center;
}
.piece {
width: 80px;
height: 80px;
float: left;
}
</style>
</head>
<body>
<div id="container"></div>
<div id="panel">
<button id="addBtn">添加</button>
<button id="flaBtn">闪烁</button>
</div>
<script src="js/mylib.js"></script>
<script>
function randomColor() {
var r = parseInt(Math.random() * 256);
var g = parseInt(Math.random() * 256);
var b = parseInt(Math.random() * 256);
return 'rgb(' + r + ',' + g + ',' + b +')';
}
(function() {
var counter = 0;
bind($('addBtn'), 'click', function() {
if (counter < 50) {
counter += 1;
var div = document.createElement('div');
div.className = 'piece';
div.style.backgroundColor = randomColor();
$('container').appendChild(div);
}
});
var timer = 0;
bind($('flaBtn'), 'click', function() {
if (!timer) {
timer = setInterval(function() {
var allPieces = $('container').children;
for (var i = 0; i < allPieces.length; i += 1) {
allPieces[i].style.backgroundColor = randomColor();
}
}, 200);
}
});
}());
</script>
</body>
</html>