0

I am attempting to set a canvas element to the size of the current window.

I did so successfully with jquery here:

function windowsize() {
    WIDTH = $("#canvas")[0].width = ($(window).width());
    HEIGHT = $("#canvas")[0].height = ($(window).height());

}

windowsize();

I cannot accomplish the same thing in plain javascript, I have as follows:

function windowsize(){
    var ctx = document.getElementbyID("canvas");
    ctx.canvas.width = window.innerWidth;
    ctx.canvas.height = window.innerHeight;
}
windowsize();

Here is a fiddle with the above: http://jsfiddle.net/Kinetic915/bWYy7/

I was also using the following page as a reference:

Resize HTML5 canvas to fit window

Thanks!

Community
  • 1
  • 1
user2138152
  • 131
  • 3
  • 10

1 Answers1

2

Typo:

document.getElementbyID

should be:

document.getElementById

and ctx has no canvas property

Updated Example: http://jsfiddle.net/bWYy7/3/

Alex
  • 76
  • 2