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');
canvasElement.width = 400;
canvasElement.height = 400;
doesn’t work. How can I resize the canvas (make it something not equal to 160*320)?

Answer by Starx

You can do it, this way.

var canvasElement = document.getElementById('yourCanvasElement');
canvasElement.width = 500;
canvasElement.height = 400;

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!