Canvas HTMLCanvasElement:HTMLCanvasElement.width属性

返回到: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

(0)
打赏 支付宝 支付宝 微信 微信
terryterry
上一篇 2023年1月5日
下一篇 2023年1月5日

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注