I have the following code in html:
<canvas id="myCanvas" width =800 height=800>
I want, instead of specifying the width
as 800
, to call the JavaScript function getWidth()
to get the width e.g.
<canvas id="myCanvas" width =getWidth() height=800>
What is the correct syntax to do it? Because what I'm doing doesn't work.
You can set the width like this :
function draw() {
var ctx = (a canvas context);
ctx.canvas.width = window.innerWidth;
ctx.canvas.height = window.innerHeight;
//...drawing code...
}