views:

80

answers:

1

I init my canvas like this:

<canvas id="canvasDiv" width="20" height="20"></canvas>

and somewhere in the code I want to resize it to it's final size:

var canvas = document.getElementById("canvasDiv");
canvas.style.width = 200;
canvas.style.height = 100;

However, any pixel I plot on my canvas is scaled (so it's not 1 pixel anymore).

How does one change the dimensions of a canvas without this scaling effect? (So programmatically)

+1  A: 

I think you just need to also set its width & height properties:

canvas.width = 200;
canvas.height = 100;
sunetos
wow... I actually checked some online DOM references to see the attributes of dom elements, and width and height were not on there. Other examples used this style trick. Thats why I used that syntax
Toad
Is there actually a proper/official dom/css reference guide? I sued this one but apparently it is not complete: http://www.javascriptkit.com/domref/elementproperties.shtml
Toad
The official spec for the canvas tag is at http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html
sunetos