-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpixel.js
More file actions
35 lines (28 loc) · 853 Bytes
/
pixel.js
File metadata and controls
35 lines (28 loc) · 853 Bytes
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
//Select color input
//Select size input
var height, width, color;
//When size is submitted by the user, call makeGrid() function
$('#sizePicker').submit(function(event){
event.preventDefault();
height = $('#input_height').val();
width = $('#input_width').val();
makeGrid(height, width);
})
function makeGrid(x,y) {
$('tr').remove();
for(var i = 1; i<= x; i++){
$('#pixel_canvas').append('<tr id=table' + i + '></tr>');
for (var j =1; j <= y; j++){
$('#table' + i).append('<td></td>');
}
}
//This adds color chosen to cell
$('td').click(function addColor(){
color = $('#colorPicker').val();
if($(this).attr('style')) {
$(this).removeAttr('style')
} else {
$(this).attr('style','background-color:' + color);
}
})
}