LOADING...

Preview

Pen ID
Unlock Campus Themeforest adv

 

Code


    Pixel Art Maker!
    
    

    
    

    


    

Lab: Pixel Art Maker

Choose Grid Size

Grid Height: Grid Width:

Pick A Color

Design Canvas

CSS
body {
    text-align: center;
    color: #1E1E1D;
    background-color: #CFDBD5;
}

h1 {
    font-family: Monoton;
    font-size: 70px;
    margin: 0.2em;
}

h2 {
    margin: 1.5em 0 0.5em;
}


/* The ":first-of-type" CSS pseudo-class represents the first element
of its type among a group of sibling elements. */

h2:first-of-type {
    margin-top: 1em;
}

table,
tr,
td {
    border: 1px solid black;
}

table {
    border-collapse: collapse;
    margin: 0 auto;
}

tr {
    height: 20px;
}

td {
    width: 20px;
}


/* Styles a specific input type using an attribute selector */

input[type=number] {
    width: 4em;
    padding: 10px;
    border: 1.5px solid #ccc;
    border-radius: 6px;
}

input[type=number]:first-of-type {
    margin-right: 20px;
}

input[type=submit] {
    cursor: pointer;
    background-color: #EFAC39;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 10px;
    margin-left: 20px;
}

input[type=submit]:hover {
    background-color: #EF9C0B;
}

input[type=color] {
    cursor: pointer;
    width: 30px;
    height: 30px;
    border:none;
    background-color: transparent;
}
JS
$('[type=submit]').on('click', function(evt) {

  var gridHeight, gridWidth;

  // When the submit button is clicked, the page reloads;
  // it is necessary to prevent this behaviour.
  evt.preventDefault();

  gridHeight = $('#input_height').val();
  gridWidth = $('#input_width').val();

  makeGrid(gridHeight, gridWidth);
});


function makeGrid( gridH, gridW ) {

  var tableColor = $('#colorPicker').val();
  var table = $('#pixel_canvas');

  var rInd = 0;
  var cInd = 0;
  var row;

  // Removes the grid from the DOM if it already exists
  if( table.children().length > 0 ) table.children().remove();

  while ( rInd < gridH ) {

    row = table.append("");

    for ( cInd = 0; cInd < gridW; cInd++ ) {

      row.append("");               // Why doesn't it work?
      //row.children().last().append('');  -> This one works!
      
    } // for loop

    rInd++;
  } // while loop
}

Description

Single-page app in JavaScript where the user can create artistic designs!
Wed, 12/27/2017 - 07:02

Related Codes

Pen ID
Pen ID
Pen ID
Square Adv