-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
34 lines (27 loc) · 967 Bytes
/
script.js
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
const container = document.querySelector(".container");
let grid = 16;
gridProtocal();
document.querySelector("#reset").addEventListener("click", () => {
reset();
});
document.querySelector("#gridSize").addEventListener("change", () => {
grid = document.querySelector("#gridSize").value;
container.style.gridTemplateColumns = `repeat(${grid}, 1fr)`;
container.style.gridTemplateRows = `repeat(${grid}, 1fr)`;
reset();
});
function gridProtocal() {
for (let i = 0; i < grid * grid; i++) {
const square = document.createElement("div");
square.classList.add("square");
container.appendChild(square);
square.addEventListener("mouseover", () => {
square.style.backgroundColor = document.querySelector("#colorPicker").value;
});
}
}
function reset() {
while (container.firstChild) {
container.removeChild(container.firstChild);}
gridProtocal();
}