HTMLCanvasElement.width
Własność HTMLCanvasElement.width
wyrażana jest w dodatniej liczbie całkowitej
odpowiada za atrybut width
(en-US) elemetu HTML <canvas> (en-US) i jest interpretowana w pikselach CSS. Jeśli atrybut nie został określony, lub została przypisana do niego nieprawidłowa wartość, np. negatywna, zostanie użyta domyślna wartość 300
.
To jedna z dwóch własności kontrolujących wielkość <canvas> (en-US), druga z nich to HTMLCanvasElement.height
.
Składnia
var pxl = canvas.width; canvas.width = pxl;
Przykłady
Wykorzystując element <canvas> (en-US):
<canvas id="canvas" width="300" height="300"></canvas>
You can get the width of the canvas with the following code:
Informacje o szerokości <canvas> (en-US) można uzyskać za pomocą kodu:
var canvas = document.getElementById('canvas');
console.log(canvas.width); // 300
Specyfikacja
Specification | Status | Comment |
---|---|---|
HTML Living Standard The definition of 'HTMLCanvasElement.width' in that specification. |
Living Standard | Brak zmian od ostatniego snapshota, HTML5 |
HTML 5.1 The definition of 'HTMLCanvasElement.width' in that specification. |
Recommendation | |
HTML5 The definition of 'HTMLCanvasElement.width' in that specification. |
Recommendation | Snapshot HTML Living Standard zawierający początkową definicje. |
Zgodność przegladarek
BCD tables only load in the browser
Zobacz też
- Interfejs definiujący tą własność,
HTMLCanvasElement
. - Inna własność kontrolujaca wielkość <canvas> (en-US),
HTMLCanvasElement.height
.