-
Notifications
You must be signed in to change notification settings - Fork 0
/
designs.js
45 lines (37 loc) · 1.29 KB
/
designs.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
// Select size input
//define variables to can draw canvas element basd on height,width
let canvasShap = document.querySelector('#pixelCanvas');
let SelectedHeight = document.querySelector('#inputHeight');
let SelectedWidth = document.querySelector('#inputWidth');
// document.getElementById("sizePicker").addEventListener("submit", myFunction);
// function myFunction() {
// makeGrid();
// }
document.getElementById('sizePicker').addEventListener('submit', function (evt) {
evt.preventDefault();
makeGrid();
})
// Select color input
let SelectedColor = document.querySelector('#colorPicker');
// When size is submitted by the user, call makeGrid()
function makeGrid() {
// Your code goes here!
//debugger;
canvasShap.innerHTML = '';
let tableHeight = SelectedHeight.value;
let tableWidth = SelectedWidth.value;
//This function to fills slected color in the cell by click.
let setColor = function (scolor) {
scolor.addEventListener('click', function () {
scolor.style.backgroundColor = SelectedColor.value;
});
}
//draw table.
for (let x = 0; x < tableHeight; x++) {
let tableTr = canvasShap.insertRow(x);
for (let y = 0; y < tableWidth; y++) {
let tableCol = tableTr.insertCell(y);
tableCol.addEventListener('click', setColor(tableCol));
}
}
};