-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
39 lines (31 loc) · 1.09 KB
/
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
35
36
37
38
39
const gridBtn = document.getElementById('grid-btn');
window.onload = function() {
let count = 256,
div,
grid = document.getElementById('grid');
for (let i = 0; i < count; i++) {
div = document.createElement('div');
div.classList.add('pixel');
div.addEventListener('mouseover', changeColor);
grid.appendChild(div);
}
};
function changeColor(){
this.classList.add('hovered');
}
function changeGrid(){
const perSide = prompt('How many squares per side? ');
perSide > 100 ? perSide = 100: perSide;
let count = perSide * perSide,
div,
grid = document.getElementById('grid');
grid.innerHTML = '';
document.documentElement.style.setProperty("--columns-row", perSide)
for (let i = 0; i < count; i++) {
div = document.createElement('div');
div.classList.add('pixel')
div.addEventListener('mouseover', changeColor)
grid.appendChild(div);
}
};
gridBtn.addEventListener('click', changeGrid); // this should generate whole new grid