Setting the canvas width attribute will clear the canvas.
If you resize the style width (e.g. canvas.style.visibility
), it will scale (usually not in such a pretty way).
If you want to make the canvas bigger but keep the elements in it as they are, I would suggest storing the canvas as an image — e.g. call the toDataURL
method to get the image, then draw that to the resized canvas with drawImage()
.