File tree Expand file tree Collapse file tree 3 files changed +98
-0
lines changed
Projects/01-Color-Changer Expand file tree Collapse file tree 3 files changed +98
-0
lines changed Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6
+ < title > Color Changer</ title >
7
+ < link rel ="stylesheet " href ="style.css ">
8
+ </ head >
9
+ < body >
10
+ < div class ="canvas ">
11
+ < div class ="heading ">
12
+ < h1 > Project 1: Color Changer</ h1 >
13
+ < h3 > Try clicking on one of the colors below to change the background color of this page!</ h3 >
14
+ </ div >
15
+
16
+ < span class ="btn " id ="grey "> </ span >
17
+ < span class ="btn " id ="white "> </ span >
18
+ < span class ="btn " id ="blue "> </ span >
19
+ < span class ="btn " id ="yellow "> </ span >
20
+ </ div >
21
+ < script src ="script.js "> </ script >
22
+ </ body >
23
+ </ html >
Original file line number Diff line number Diff line change
1
+ // Select Color and canvas
2
+ const buttons = document . querySelectorAll ( '.btn' ) ;
3
+ const canvas = document . querySelector ( '.canvas' ) ;
4
+
5
+ buttons . forEach ( ( button ) => {
6
+ console . log ( button ) ;
7
+ button . addEventListener ( 'click' , ( e ) => {
8
+
9
+ const validColor = [ 'grey' , 'white' , 'blue' , 'yellow' ] ;
10
+ const color = e . target . id ;
11
+
12
+ if ( validColor . includes ( color ) ) {
13
+ canvas . style . backgroundColor = color
14
+ }
15
+
16
+
17
+ // if (e.target.id === 'grey') {
18
+ // canvas.style.backgroundColor = e.target.id;
19
+ // }
20
+ // else if (e.target.id === 'white') {
21
+ // canvas.style.backgroundColor = e.target.id;
22
+ // }
23
+ // else if (e.target.id === 'blue') {
24
+ // canvas.style.backgroundColor = e.target.id;
25
+ // }
26
+ // else if (e.target.id === 'yellow') {
27
+ // canvas.style.backgroundColor = e.target.id;
28
+ // }
29
+ } ) ;
30
+ } )
31
+
32
+
33
+ // Apply color to canvas
Original file line number Diff line number Diff line change
1
+ * {
2
+ font-family : monospace;
3
+ margin : 0 ;
4
+ }
5
+
6
+ span {
7
+ display : block;
8
+ }
9
+
10
+ .canvas {
11
+ text-align : center;
12
+ height : 100vh ;
13
+ }
14
+
15
+ .heading h1 , .heading h3 {
16
+ margin-bottom : 20px ;
17
+ }
18
+
19
+ .btn {
20
+ width : 100px ;
21
+ height : 100px ;
22
+ border : solid black 2px ;
23
+ display : inline-block;
24
+ cursor : pointer;
25
+ }
26
+
27
+ # grey {
28
+ background : grey;
29
+ }
30
+
31
+ # white {
32
+ background : white;
33
+ }
34
+
35
+ # blue {
36
+ background : blue;
37
+ }
38
+
39
+ # yellow {
40
+ background : yellow;
41
+ }
42
+
You can’t perform that action at this time.
0 commit comments