返回到:Canvas API:HTMLCanvasElement
HTMLCanvasElement.width 属性是一个对应 <canvas> 元素 CSS 像素 width 的正整数。当这个属性没有指定时,或者被赋予一个不合法的值,比如一个负值,默认使用 300.
这是其中之一,另一个是 HTMLCanvasElement.height, 它们控制了 canvas 的大小尺寸。
语法
var pxl = canvas.width;
canvas.width = pxl;示例
有这样一个 <canvas> 元素:
<canvas id="canvas" width="300" height="300"></canvas>你能够通过下面的代码得到 canvas 的宽度:
var canvas = document.getElementById('canvas');
console.log(canvas.width); // 300返回到:Canvas API:HTMLCanvasElement
作者:terry,如若转载,请注明出处:https://www.web176.com/canvas_api/7863.html
支付宝
微信