1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
---
title: HTMLCanvasElement.width
slug: Web/API/HTMLCanvasElement/width
translation_of: Web/API/HTMLCanvasElement/width
---
<div>
<div>
<div>{{APIRef("Canvas API")}}</div>
<div> </div>
<div>
<p>Własność <strong><code>HTMLCanvasElement.width </code></strong>wyrażana jest w dodatniej <code>liczbie całkowitej </code>odpowiada za atrybut {{htmlattrxref("width", "canvas")}} elemetu HTML {{HTMLElement("canvas")}} 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ść <code>300</code>.</p>
<p>To jedna z dwóch własności kontrolujących wielkość {{HTMLElement("canvas")}}, druga z nich to {{domxref("HTMLCanvasElement.height")}}.</p>
</div>
</div>
</div>
<h2 id="Syntax" name="Syntax">Składnia</h2>
<pre class="syntaxbox"><var>var <em>pxl</em> = <em>canvas</em></var>.width;
<em>canvas</em>.width = <em>pxl</em>;
</pre>
<h2 id="Przykłady">Przykłady</h2>
<p>Wykorzystując element {{HTMLElement("canvas")}}:</p>
<pre class="brush: html"><canvas id="canvas" width="300" height="300"></canvas>
</pre>
<p>You can get the width of the canvas with the following code:</p>
<p>Informacje o szerokości {{HTMLElement("canvas")}} można uzyskać za pomocą kodu:</p>
<pre class="brush: js">var canvas = document.getElementById('canvas');
console.log(canvas.width); // 300
</pre>
<h2 id="Specyfikacja">Specyfikacja</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
<tr>
<td>{{SpecName('HTML WHATWG', "scripting.html#attr-canvas-width", "HTMLCanvasElement.width")}}</td>
<td>{{Spec2('HTML WHATWG')}}</td>
<td>Brak zmian od ostatniego snapshota, {{SpecName('HTML5 W3C')}}</td>
</tr>
<tr>
<td>{{SpecName('HTML5.1', "scripting-1.html#attr-canvas-width", "HTMLCanvasElement.width")}}</td>
<td>{{Spec2('HTML5.1')}}</td>
<td> </td>
</tr>
<tr>
<td>{{SpecName('HTML5 W3C', "scripting-1.html#attr-canvas-width", "HTMLCanvasElement.width")}}</td>
<td>{{Spec2('HTML5 W3C')}}</td>
<td>Snapshot {{SpecName('HTML WHATWG')}} zawierający początkową definicje.</td>
</tr>
</tbody>
</table>
<h2 id="Zgodność_przegladarek">Zgodność przegladarek</h2>
<p>{{Compat("api.HTMLCanvasElement.width")}}</p>
<h2 id="See_Also" name="See_Also">Zobacz też</h2>
<ul>
<li>Interfejs definiujący tą własność, {{domxref("HTMLCanvasElement")}}.</li>
<li>Inna własność kontrolujaca wielkość {{HTMLElement("canvas")}}, {{domxref("HTMLCanvasElement.height")}}.</li>
</ul>
|