The HTML5
What I\'m trying to accompl
Like said by sethobrien a canvas
element has TWO pairs width/height of attributes.
canvas.width
/ canvas.height
are about the size in pixel of the buffer that will contains the result of drawing commands.
canvas.style.width
/ canvas.style.height
are about the size used to show the canvas object in the browser window and they can be in any of the units supported by css.
You can indeed set canvas.width
and canvas.height
just once, do the drawing in the canvas, setting the style size parameters in percentage and then forget about redrawing the canvas content. Of course this means that the browser will just do the scaling itself like for a regular image loaded from the network so the visible result will show pixel scaling artifacts.
You need to redraw the canvas content after the resize of the canvas element only if you want pixel-perfect results.