I want to resize the canvas element so that if fits its parent, whether it's <body>
("full-screen") or some <div>
for instance. This is my attempt:
// called at each frame
function update() {
var canvasNode = document.getElementById('mycanvas');
canvasNode.width = canvasNode.parentNode.clientWidth;
canvasNode.height = canvasNode.parentNode.clientHeight;
}
For some reason, the canvas doesn't stop growing! Maybe client*
aren't the right parameters?
See the code in action here: http://jsfiddle.net/ARKVD/24/