HTMLCanvasElement.height
property is a positive
integer
反射
height
HTML attribute of the
<canvas>
element interpreted in CSS pixels. When the attribute is not specified, or if it is set to an invalid value, like a negative, the default value of
150
被使用。
This is one of the two properties, the other being
HTMLCanvasElement.width
, that controls the size of the canvas.
var pxl = canvas.height; canvas.height = pxl;
Given this
<canvas>
元素:
<canvas id="canvas" width="300" height="300"></canvas>
You can get the height of the canvas with the following code:
var canvas = document.getElementById('canvas');
console.log(canvas.height); // 300
| 规范 | 状态 | 注释 |
|---|---|---|
|
HTML 实时标准
The definition of 'HTMLCanvasElement.height' in that specification. |
实时标准 | 无变化从最新快照起, HTML5 |
|
HTML 5.1
The definition of 'HTMLCanvasElement.height' in that specification. |
推荐 | |
|
HTML5
The definition of 'HTMLCanvasElement.height' in that specification. |
推荐 | Snapshot of the HTML 实时标准 containing the initial definition. |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
height
|
Chrome 1 | Edge 12 | Firefox 1.5 | IE 9 | Opera 9 | Safari 3 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 |
完整支持
HTMLCanvasElement
.
HTMLCanvasElement.width
.