cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <!DOCTYPE html>
<html>
<head>
    <title>Pixel Art Maker!</title>
  
  <link href="https://fonts.googleapis.com/css?family=Overlock+SC" rel="stylesheet">
  
<link href="https://fonts.googleapis.com/css?family=Josefin+Slab" rel="stylesheet">
    
  <link rel="stylesheet" href="styles.css">
    
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

  <script type="text/javascript" src="html2canvas.js"></script>

  <meta charset="UTF-8">
  
</head>
    
<body>
    <h1>Pixel Art Maker</h1>

    <h3 class="overlock">Choose Grid Size</h3>
    <p></p>
    <form class="overlock" id="sizePicker">
        Grid Height:
        <input type="number" id="inputHeight" name="height" min="1" max="50" value="10">
        Grid Width:
        <input type="number" id="inputWidth" name="width" min="1" max="50" value="10">
        <input type="submit" id="submitted">
      <button type="button" id="clear">Clear</button>
    </form>

    <h4 class="overlock">Pick A Color</h4>
    <input type="color" id="colorPicker">

    <h4 class="overlock">Design Canvas</h4>
    <table id="pixelCanvas"> </table>
  <p></p>
    
    </form>
    
</body>
</html>

            
          
!
            
              body {
    text-align: center;
  background-image:url("https://st2.depositphotos.com/1011833/6677/i/950/depositphotos_66776311-stock-photo-old-blank-vintage-nautical-map.jpg");
}

h1 {
    font-family: "Overlock SC", "Josefin Slab", arial;
    font-size: 75px;
    margin: 0.30em;
}

h3 {
    margin: 1em 0 0.30em;
    font-family: "Overlock SC", "Josefin Slab", arial;
}

h3:first-of-type {
    margin-top: 0.50em;
}

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

table {
    border-collapse: collapse;
    margin: 0 auto;
    background-color: #fffff0;
}

tr {
    height: 20px;
}

td {
    width: 20px;
}

input[type=number] {
    width: 6em;
}

.overlock {
  font-family: "Overlock SC", "Josefin Slab", arial;
}

            
          
!
            
              //set element table to variable canvas
var canvas = $('#pixelCanvas');

//setting a default grid

for (var r = 0; r < $('#inputHeight').val(); r++) {
  //use variable row as placeholder for the child element
  var row = $("<tr></tr>");
    //create column through 2nd loop
    for (var c = 0; c < $('#inputWidth').val(); c++) {
      row.append("<td></td>");
    }
  //actual creation of the child element
  canvas.append(row);
}

//change cursor upon mouse over event on Clear
$('#clear').on('mouseover', function(){
  $(this).css('cursor', 'pointer');
});

//adding the clear event that empties the canvas
$('#clear').on('click',function() {
  canvas.empty();
});

//change cursor upon mouse over event on Color Picker
$('#colorPicker').on('mouseover',function() {
  $(this).css('cursor', 'pointer');
});

function makeGrid() {
//clear the canvas
canvas.empty();
// Select size input
var gridHeight = $('#inputHeight').val();
var gridWidth = $('#inputWidth').val();

//validate maximum width and height  
if(gridHeight > 50 || gridWidth > 50){
		alert('The maximum limit is 50. Try selecting between 1 & 50!');
		return;
	}
//create row through the 1st loop
for (var r = 0; r < gridHeight; r++) {
  //use variable row as placeholder for the child element
  var row = $("<tr></tr>");
  
    //create column through 2nd loop
    for (var c = 0; c < gridWidth; c++) {
      row.append("<td></td>");
    }
  //actual creation of the child element
  canvas.append(row);
  }
  event.preventDefault();
}

// When size is submitted by the user, call makeGrid()
$('#submitted').on('click', makeGrid);
//change cursor upon mouse over event on Submit 
$('#submitted').on('mouseover', function(){
  $(this).css('cursor', 'pointer');
});

//change cursor upon mouse over event on the canvas
canvas.on('mouseover','td',function() {
  $(this).css('cursor', 'pointer');
});

canvas.on('click', 'td', function(){
//get color value from the color picker element
  var color = $('#colorPicker').val();

  //validate if cell has been colored
  if($(this).attr('class') === 'clicked')
    {
      //set cell color to the default color
      $(this).css('backgroundColor', '#f2f2f2');
      //remove the 'clicked' class from the cell
      $(this).removeClass('clicked');
    }
  //apply the selected color if cell is unclicked
  else {
      $(this).css('backgroundColor', color);
      $(this).addClass('clicked');
  }
});








            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console