aboutsummaryrefslogtreecommitdiff
path: root/files/pt-br/web/api/htmlcanvaselement/height/index.html
blob: 536f331fa213d01d81ac75ffb6183343c4dd19c1 (plain)
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.height
slug: Web/API/HTMLCanvasElement/height
tags:
  - API
  - Canvas
  - HTMLCanvasElement
  - Propriedade
  - altura
translation_of: Web/API/HTMLCanvasElement/height
---
<div>
<div>
<div>{{APIRef("Canvas API")}}</div>
</div>
</div>

<p>A propriedade <strong><code><span>HTMLCanvasElement.height</span></code></strong> é um <code>inteiro</code> positivo que reflete o atributo {{htmlattrxref("height", "canvas")}} do elemento HTML {{HTMLElement("canvas")}} interpretado em pixels no CSS. Quando o atributo não é especificado, ou se for definido como um valor inválido, como um <code>inteiro</code> negativo, o valor padrão de <code>150</code> será usado.</p>

<p>Essa é uma de duas propriedades, que controla o tamanho do canvas, sendo a outra {{domxref("HTMLCanvasElement.width")}}.</p>

<h2 id="Syntax" name="Syntax">Sintaxe</h2>

<pre class="syntaxbox"><var>var <em>pxl</em> = <em>canvas</em></var>.height;
<em>canvas</em>.height = <em>pxl</em>;
</pre>

<h2 id="Exemplos">Exemplos</h2>

<p>Dado este elemento {{HTMLElement("canvas")}}:</p>

<pre class="brush: html">&lt;canvas id="canvas" width="300" height="300"&gt;&lt;/canvas&gt;
</pre>

<p>Você pode capturar a altura do canvas com o seguinte código:</p>

<pre class="brush: js">var canvas = document.getElementById('canvas');
console.log(canvas.height); // 300
</pre>

<h2 id="Especificações">Especificações</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-height", "HTMLCanvasElement.height")}}</td>
   <td>{{Spec2('HTML WHATWG')}}</td>
   <td>No change since the latest snapshot, {{SpecName('HTML5 W3C')}}</td>
  </tr>
  <tr>
   <td>{{SpecName('HTML5.1', "scripting-1.html#attr-canvas-height", "HTMLCanvasElement.height")}}</td>
   <td>{{Spec2('HTML5.1')}}</td>
   <td> </td>
  </tr>
  <tr>
   <td>{{SpecName('HTML5 W3C', "scripting-1.html#attr-canvas-height", "HTMLCanvasElement.height")}}</td>
   <td>{{Spec2('HTML5 W3C')}}</td>
   <td>Snapshot of the {{SpecName('HTML WHATWG')}} containing the initial definition.</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Compatibilidade com navegadores</h2>



<p>{{Compat("api.HTMLCanvasElement.height")}}</p>

<h2 id="See_Also" name="See_Also">Veja também</h2>

<ul>
 <li>A interface a define, {{domxref("HTMLCanvasElement")}}.</li>
 <li>Outra propriedade para controlar o tamanho do canvas, {{domxref("HTMLCanvasElement.width")}}.</li>
</ul>