Reputation: 131
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!
Upvotes: 0
Views: 2265
Reputation: 76
Typo:
document.getElementbyID
should be:
document.getElementById
and ctx has no canvas property
Updated Example: http://jsfiddle.net/bWYy7/3/
Upvotes: 2