-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
52 lines (38 loc) · 1.17 KB
/
Copy pathscript.js
File metadata and controls
52 lines (38 loc) · 1.17 KB
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
var container = document.querySelector('.container');
let currentColor = "#444";
let buttonState = false;
let gridSize = 16;
const colorPicker = document.getElementById('colorPicker')
var grid = document.getElementById('grid');
for(var j = 0; j < gridSize; j++ ){
const line = document.createElement('div');
line.setAttribute('class', 'line');
container.appendChild(line);
for (var i = 0; i < gridSize; i++) {
var newGrid = document.createElement('div');
newGrid.setAttribute('class', 'grid');
container.appendChild(newGrid);
}
}
let block = document.querySelectorAll(".grid");
beginGrid(block)
function beginGrid(block){
block.forEach(block => {
block.addEventListener('mouseenter', () => {
block.style.backgroundColor = currentColor;
});
});
}
function clear(block){
block.forEach(block => {
block.style.cssText = "background-color: white";
});
}
let resetBtn = document.querySelector('.reset');
resetBtn.addEventListener('click', () => {
clear(block);
});
colorPicker.oninput = (e) => setCurrentColor(e.target.value);
function setCurrentColor(newColor) {
currentColor = newColor;
}