views:

32

answers:

1

how can i change the size of an html canvas through a function? i tried Width=123;" and canvas.style.Width=123 canvas.width=123 neither of them worked heres the HTML code for the canvas <CANVAS id="canvas" width="460px" height="800px"></CANVAS> and in the css canvasarea { width: 460px; height: 800px;

+1  A: 

the <canvas> element supports the width attribute.

example: <canvas width="123"></canvas>

to change the width with javascript do something like:

<canvas id="myCanvas"></canvas>

<script type="javascript">

function changeCanvasWidth() {
    myCanvas = document.getElementById("myCanvas");
    myCanvas.style.width="123px";
}
</script>

reference: http://www.w3schools.com/html5/tag_canvas.asp

jordanstephens