开发者

How can i change the size of a HTML canvas

开发者 https://www.devze.com 2023-01-11 09:29 出处:网络
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 i

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">开发者_如何学Python;</CANVAS> and in the css canvasarea { width: 460px; height: 800px;


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

0

精彩评论

暂无评论...
验证码 换一张
取 消