-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
47 lines (36 loc) · 1.13 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
40
41
42
43
44
45
const grid = document.querySelector('.grid');
const r = document.querySelector(':root');
const button = document.querySelector('#clearGrid');
let gridNumb;
let isDown = false;
document.addEventListener("mousedown", function() {
isDown = true;
});
document.addEventListener("mouseup", function(){
isDown = false;
})
function createGrid(size = 250){
console.log(size)
r.style.setProperty('--size', size);
gridNumb = size * size;
for(let i = 0; i < gridNumb; i++){
let gridItem = document.createElement('div');
gridItem.classList.add('gridItem');
gridItem.addEventListener('mouseover', function(e){
console.log(isDown)
if(isDown == true){
e.target.classList.add('drawn');
}
});
grid.appendChild(gridItem);
}
let itemNum = document.querySelectorAll('.gridItem');
console.log(itemNum.length)
}
createGrid();
button.addEventListener("click", function(){
let itemNum = document.querySelectorAll('.drawn');
for(let i = 0; i < itemNum.length; i++){
itemNum[i].classList.remove('drawn');
}
});