-
Notifications
You must be signed in to change notification settings - Fork 0
/
designs.js
43 lines (36 loc) · 1.25 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
// Select color input
// Select size input
var mouseDown = false;
// draws the grid after user submits height and width
function makeGrid() {
var rows = document.getElementById('input_height').value; //the height value
var columns = document.getElementById('input_width').value; //the width value
$('#pixel_canvas').empty() //clears the grid if the user enters new values
//draws the grid based on user input
for (var row = 0; row < rows; row++){
$('#pixel_canvas').append('<tr class="row"></tr>'); //adds new row
for (var column = 0; column < columns; column++){
var rowElement = $('.row').last();
$(rowElement).append('<td class="cell"></td>'); //adds new cells
}
}
}
$('#sizePicker').submit(function(ev){
ev.preventDefault(); //prevents the submit button from submitting data
makeGrid();
});
$(document).mousedown(function(){
mouseDown = true;
}).mouseup(function(){
mouseDown = false;
});
$('#pixel_canvas').on('mouseout', 'td', function(){
if(mouseDown){
var color = document.getElementById('colorPicker').value;
$(this).css('background-color', color);
}
});
$('#pixel_canvas').on('click', 'td', function(){
var color = document.getElementById('colorPicker').value;
$(this).css('background-color', color);
});