-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdesigns.js
More file actions
42 lines (34 loc) · 1.12 KB
/
Copy pathdesigns.js
File metadata and controls
42 lines (34 loc) · 1.12 KB
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
//Select color input
let colorInput = document.getElementById('input[type=color]');
//Select size input
let submit1 = document.getElementById('sizePicker');
// When size is submitted by the user , call makeGrid()
submit1.addEventListener('click', function(e) {
e.preventDefault();
makeGrid();
});
function makeGrid() {
let gridRow = document.getElementsByTagName('tr');
while (gridRow[0]) {
gridRow[0].parentNode.removeChild(gridRow[0]);
}
let pixelCanvas = document.getElementById('pixelCanvas');
let gridHeight = document.getElementById('inputHeight').value;
let gridWidth = document.getElementById('inputWeight').value;
for (let row = 1; row <= gridHeight; row++) {
let tr = document.createElement('tr');
pixelCanvas.appendChild (tr);
for (let col = 1; col <= gridWidth; col++) {
let td = document.createElement('td');
pixelCanvas.lastChild.appendChild(td);
}
}
$('td').click(function() {
let color = $('#colorPicker').val();
if ($(this).attr('style')) {
$(this).removeAttr('style');
}else {
$(this).attr('style', 'background-color:' + color);
}
});
}