-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJavaScript.js
61 lines (46 loc) · 1.51 KB
/
JavaScript.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
46
47
48
49
50
51
52
53
54
55
56
57
58
let empty = true;
//this is a boolean value used to see if we need to reset the canvas if the screen resizes
const container = document.querySelector(".container");
let mouseDown = 0;
document.body.onmousedown = function() {
mouseDown = 1;
}
document.body.onmouseup = function() {
mouseDown = 0;
}
function createPixels(num){
if(empty == false){
while (container.hasChildNodes()) {
container.removeChild(container.firstChild);
}
empty = true;
createPixels(num);
}
else{
for(let j = 0; j< num; j++){
let row = document.createElement("div");
row.classList.add('row');
for(let i = 0;i<num;i++){
let pixel = document.createElement("div");
pixel.classList.add("pixel");
pixel.addEventListener("mouseover", function(){
if(mouseDown == 1){
pixel.classList.add("colorChange");
}
});
row.appendChild(pixel);
}
container.appendChild(row);
}
empty = false;
}
}
function resetColor(){
//double for loop through and remove the class colorChange
//needs to be given a container with stuff in it
}
const btns = document.querySelectorAll(".btn");
btns.forEach(btn => btn.addEventListener('click', function(){
createPixels(btn.value);
}));
//here's the div that we are gonna work w/ and we give it a class to make ti sketch