-
Notifications
You must be signed in to change notification settings - Fork 0
/
designs.js
44 lines (34 loc) · 1.15 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
// Select inputHeight(number of rows)
var heightInput = $("#inputHeight");
// Select inputHeight(number of columns)
var widthInput = $("#inputWidth");
// Select color input
var colorInput = $("#colorPicker");
// When size is submitted by the user, call makeGrid()
function makeGrid() {
var heightValue = heightInput.val();
var widthValue = widthInput.val();
var pixelCanvas = $("#pixelCanvas");
// clears previously built table if any exists
pixelCanvas.children().remove();
// grid is built
for (var row = 0; row < heightValue; row++) {
//add a new row
pixelCanvas.append("<tr></tr>");
//add all the columns in the row
for (var column = 0; column < widthValue; column++) {
$(pixelCanvas.children()[row]).append("<td></td>");
}
}
}
//Background color of the cell changes, with respective chosen color
$("table").on("click", "td", function() {
$(this).css("backgroundColor", colorInput.val());
});
// When the size is submitted by the user, we call makeGrid()
var form = $("#sizePicker");
form.submit(function(event) {
// This stops the page from refreshing upon submit
event.preventDefault();
makeGrid();
});