-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathColorClicker.html
98 lines (92 loc) · 3.46 KB
/
ColorClicker.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<!DOCTYPE html>
<html>
<head>
<title>The Codingdojo ColorClicker!</title>
<script type="text/javascript" src='http://code.jquery.com/jquery-1.10.2.min.js'></script>
<script type="text/javascript">
function random_color() {
var rgb = ['a', 'b', 'c', 'd', 'e', 'f', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
color = '#' //this is what we'll return!
for (var i = 0; i < 6; i++) {
x = Math.floor((Math.random() * 16))
color += rgb[x];
}
return color;
}
$(document).ready(function () {
random_color();
$('.large_box, .bottom_box').click(function () {
$('.large_box').css('background', random_color());
$('.bottom_box').css('background', random_color());
$('.large_box').children().css('background', random_color());
$('.bottom_box').children().css('background', random_color());
//alert('you clicked the big box!');
//comment this out when you have figured out what event.stopPropagation is used for
})
$('.side_box').click(function (event) {
$(this).siblings().css('background', random_color());
event.stopPropagation();
})
$('.middle_box').click(function (event) {
$(this).parent().css('background', random_color());
event.stopPropagation();
})
});
</script>
<style type="text/css">
* {
font-family: sans-serif;
}
h2,
h1,
h3 {
text-align: center;
}
.large_box {
margin: 0px auto;
margin-top: 30px;
background-color: lightblue;
width: 1200px;
height: 300px;
}
.large_box div {
background-color: blue;
display: inline-block;
width: 350px;
height: 130px;
margin: 60px 20px;
}
.bottom_box {
margin: 0px auto;
margin-top: 30px;
background-color: lightblue;
width: 1200px;
height: 300px;
}
.bottom_box div {
background-color: blue;
display: inline-block;
width: 350px;
height: 130px;
margin: 60px 20px;
}
</style>
</head>
<body>
<h1>The Codingdojo ColorClicker! </h1>
<div class='large_box'>
<div class='side_box'></div>
<div class='middle_box'></div>
<div class='side_box'></div>
</div>
<div class='bottom_box'>
<div class='side_box'></div>
<div class='middle_box'></div>
<div class='side_box'></div>
</div>
<h2>Rules</h2>
<h3>1. Clicking the big box should change background colors of both the small and large boxes!</h3>
<h3>2. Clicking the middle small box should change the color of the big box!</h3>
<h3>3. Clicking the left or right small box should change the color of that box's siblings</h3>
</body>
</html>