1
1
document . addEventListener ( "DOMContentLoaded" , function ( ) {
2
2
let grid = document . getElementById ( "grid" )
3
- let gridSize = 24
4
- let colorNames = [ "red" , "orange" , "yellow" , "green" , "blue" , "purple" , "black" , "white" , "SaddleBrown" ]
3
+ let container = document . getElementById ( "container" )
4
+ let pixels = 24
5
+ let colorNames = [ "red" , "orange" , "yellow" , "green" , "blue" , "purple" , "black" , "white" , "gray" , "SaddleBrown" ]
5
6
let currentColor = ""
6
7
let cell , row , col , colorCell , indicator
7
8
9
+ // pixels * width of each pixel (20px) + (pixels + 1) * border (1px) = total grid size
10
+ grid . style . width = ( pixels * 21 + 1 ) + "px"
11
+ grid . style . height = ( pixels * 21 + 1 ) + "px"
12
+ container . style . width = ( pixels * 21 + 50 ) + "px"
13
+
8
14
function changeColor ( event ) {
9
15
event . target . style . backgroundColor = currentColor
10
16
}
@@ -15,22 +21,21 @@ document.addEventListener("DOMContentLoaded", function () {
15
21
}
16
22
17
23
function makeGrid ( ) {
18
- for ( let rows = 0 ; rows < gridSize ; rows ++ ) {
24
+ for ( let rows = 0 ; rows < pixels ; rows ++ ) {
19
25
row = document . createElement ( "div" )
20
26
row . className = "row"
21
- // row.style.height = 100/gridSize + "%"
22
- for ( let cols = 0 ; cols < gridSize ; cols ++ ) {
27
+
28
+ for ( let cols = 0 ; cols < pixels ; cols ++ ) {
23
29
cell = document . createElement ( "div" )
24
30
cell . className = "cell"
25
31
26
- // if (rows === 0) {
27
- // cell.style.borderTop = "1px solid black"
28
- // }
29
- // if (cols === 0) {
30
- // cell.style.borderLeft = "1px solid black"
31
- // }
32
+ if ( rows === 0 ) {
33
+ cell . style . borderTop = "1px solid black"
34
+ }
35
+ if ( cols === 0 ) {
36
+ cell . style . borderLeft = "1px solid black"
37
+ }
32
38
33
- // cell.style.width = 100/gridSize + "%"
34
39
row . appendChild ( cell )
35
40
}
36
41
grid . appendChild ( row )
@@ -54,6 +59,5 @@ document.addEventListener("DOMContentLoaded", function () {
54
59
55
60
indicator = document . createElement ( "div" )
56
61
indicator . className = "indicator"
57
- indicator . textContent = "current color"
58
62
palette . appendChild ( indicator )
59
63
} )
0 commit comments