Created
May 25, 2018 10:36
-
-
Save johirbuet/13098a533d3081756cc248d16707ce68 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function makeGrid() { | |
console.log("makeGrid is running!") | |
// Select size input | |
let canvas, cell, gridHeight, gridWidth, rows; | |
canvas = $('#pixelCanvas'); | |
gridHeight = $('#inputHeight').val(); | |
gridWidth = $('#inputWidth').val(); | |
canvas.empty(); | |
for (x = 0; x < gridHeight; x++) { | |
canvas.append('<tr></tr>'); | |
} | |
rows = $('tr'); | |
for (y = 0; y < gridWidth; y++) { | |
rows.append('<td></td>'); | |
} | |
cell = canvas.find('td'); | |
// When td is clicked by the user, change color of td | |
cell.click(function() { | |
// Select color input | |
console.log("changeColor is running!"); | |
var color; | |
color = $("#colorPicker").val(); | |
$(this).attr('bgcolor', color); | |
}); | |
} | |
// When size is submitted by the user, call makeGrid() | |
var submitQuery; | |
submitQuery = $('input[type="submit"]') | |
submitQuery.click(function(event) { | |
event.preventDefault(); | |
makeGrid(); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment