March 9, 2013
Javascript Canvas Sizes
Question by user1460819
I have a canvas on a HTML page:
<canvas id="canvas" class="canvas"></canvas>
Attributes width and height stretch the canvas into a certain field, but do not resize it (so, var canvasElement = document.getElementById('canvas');
doesn’t work. How can I resize the canvas (make it something not equal to 160*320)?
canvasElement.width = 400;
canvasElement.height = 400;
Answer by Starx
You can do it, this way.
var canvasElement = document.getElementById('yourCanvasElement');
canvasElement.width = 500;
canvasElement.height = 400;