Pen Settings

HTML

CSS

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

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <canvas id="wall"></canvas>
              
            
!

CSS

              
                body {
  position: absolute;
  width: 100%;
  height: 100%;
}
/* canvas {
  width: 300px;
  height: 300px;
} */
              
            
!

JS

              
                // --------------------------
// Setup Canvas / Inital Vars
// --------------------------

// canvas
var c = $('#wall');
// get canvas context so we can draw on it later
var ctx = c[0].getContext('2d');
// image(s) we will be drawing...
var wall_image_urls = [
  'http://patterninteractive.com/heritage-wall/images/sections-1024/section_01.jpg',
  'http://patterninteractive.com/heritage-wall/images/sections-1024/section_02.jpg',
  'http://patterninteractive.com/heritage-wall/images/sections-1024/section_03.jpg',
  'http://patterninteractive.com/heritage-wall/images/sections-1024/section_04.jpg',
  'http://patterninteractive.com/heritage-wall/images/sections-1024/section_05.jpg',
  'http://patterninteractive.com/heritage-wall/images/sections-1024/section_06.jpg',
  'http://patterninteractive.com/heritage-wall/images/sections-1024/section_07.jpg',
  'http://patterninteractive.com/heritage-wall/images/sections-1024/section_08.jpg',
  'http://patterninteractive.com/heritage-wall/images/sections-1024/section_09.jpg',
  'http://patterninteractive.com/heritage-wall/images/sections-1024/section_10.jpg',
  'http://patterninteractive.com/heritage-wall/images/sections-1024/section_11.jpg',
  'http://patterninteractive.com/heritage-wall/images/sections-1024/section_12.jpg',
  'http://patterninteractive.com/heritage-wall/images/sections-1024/section_13.jpg',
  'http://patterninteractive.com/heritage-wall/images/sections-1024/section_14.jpg',
  'http://patterninteractive.com/heritage-wall/images/sections-1024/section_15.jpg',
  'http://patterninteractive.com/heritage-wall/images/sections-1024/section_16.jpg',
  'http://patterninteractive.com/heritage-wall/images/sections-1024/section_17.jpg',
  'http://patterninteractive.com/heritage-wall/images/sections-1024/section_18.jpg',
  'http://patterninteractive.com/heritage-wall/images/sections-1024/section_19.jpg',
  'http://patterninteractive.com/heritage-wall/images/sections-1024/section_20.jpg'
];
var image_ready = false;

function resize_canvas() {
  var winWidth = $('body').outerWidth();
  var winHeight = $('body').outerHeight();
  c[0].width = winWidth;
  c[0].height = winHeight;
  
  // try playing around with these values to see how it affects the canvas
  // c[0].width = 400;
  // c[0].height = 200;
  // c.css({
  //   width: 600+'px',
  //   height: 200+'px'
  // });
}
// immediately resize canvas  
resize_canvas();
 
// resize canvas again if window is resized
var debounce_resize;
$(window).on('resize orientationchange', function(){
  // The timeout acts as a debounce as well has a timeout for mobile devices as they take about 2-300 ms to complete an orientationchange
  clearTimeout(debounce_resize);
  debounce_resize = setTimeout(function(){
    resize_canvas();
    // we have to now redraw the canvas or what is on it may be stretched
    if( image_ready ) { // lets make sure the images have been loaded
      draw();
    }
  }, 300);
});

// --------------------------
// load a wall image
// --------------------------

var wall_image_data;
wall_image = new Image();
// make sure you add the onload event before the src or the image may load be fire this func is defined
wall_image.onload = function(){
  imgWidth = this.width;
  imgHeight = this.height; 
  
  // store image obj in array
  wall_image_data = {
    img: this, // image obj to be drawn by canvas
    imgWidth: imgWidth,
    imgHeight: imgHeight
  }
  
  image_ready = true;
  
  // draw the image
  draw();  
};
wall_image.src = wall_image_urls[0];

// function draw the image
function draw() {
  // get the image/canvas ratio
  var wallHeight = c.height();
 
  // draw away...
  ctx.drawImage(wall_image_data.img, 0, 0, wall_image_data.imgWidth,wall_image_data.imgHeight);
}
              
            
!
999px

Console