aboutsummaryrefslogtreecommitdiff
path: root/files/zh-tw/web/html/element/canvas/index.html
blob: 5618e2fc5c42e7d1d5efdd76d7767cf30aa6c4c9 (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
---
title: <canvas>
slug: Web/HTML/Element/canvas
translation_of: Web/HTML/Element/canvas
---
<p>這個 <strong>HTML <code>&lt;canvas&gt;</code> 元素</strong> 可以被使用於對腳本程式(JaveScript) 繪圖 .舉例來說, 它能用來畫圖,組合照片,甚至作動畫. 你也許(應該) 在&lt;canvas&gt;區段內提供替代方案的內容 .這內容將能被一些不支援&lt;canvas&gt;以及無法使用Javescript功能的瀏覽器所渲染 .</p>

<p>更多文章關於canvas, 請參考 <a href="/en-US/docs/Web/API/Canvas_API">canvas 主題</a></p>

<table class="properties">
 <tbody>
  <tr>
   <th scope="row"><a href="/en-US/docs/HTML/Content_categories">Content 分類</a></th>
   <td><a href="/en-US/docs/HTML/Content_categories#Flow_content">流程式content</a>, <a href="/en-US/docs/HTML/Content_categories#Phrasing_content">段落式content</a>, <a href="https://developer.mozilla.org/en-US/docs/HTML/Content_categories#Embedded_content">強調式content</a>, 可見式 content.</td>
  </tr>
  <tr>
   <th scope="row">
    <p>被允許通過的內容</p>
   </th>
   <td>
    <p>除了子元素不是 &lt;a&gt;的元素、 &lt;button&gt;的元素、&lt;input&gt;的元素屬性是<code>checkbox</code>, <code>radio</code>, 或 <code>button</code> 之外且是透明內容模型但不是<a href="/en-US/docs/HTML/Content_categories#Interactive_content">互動式content</a></p>
   </td>
  </tr>
  <tr>
   <th scope="row">Tag 省略</th>
   <td>不能省略標籤&lt;canvas&gt; &lt;/canvas&gt;</td>
  </tr>
  <tr>
   <th scope="row">被允許通過的父親元素</th>
   <td>
    <p>任何<a href="/en-US/docs/HTML/Content_categories#Phrasing_content">強調式content</a>的元素皆可通過</p>
   </td>
  </tr>
  <tr>
   <th scope="row">DOM 介面</th>
   <td>HTMLCanvasElement</td>
  </tr>
 </tbody>
</table>

<h2 id="屬性">屬性</h2>

<p>這個元素的屬性包含全域屬性</p>

<dl>
 <dt>{{htmlattrdef("height")}}</dt>
 <dd>在CSS 中以 pixels 表示 座標的空間<strong>高度</strong>(預設是150)</dd>
 <dt>{{htmlattrdef("moz-opaque")}} {{non-standard_inline}}</dt>
 <dd>讓canvas知道這個因素是否為半透明的。如果 canvas 知道不是半透明,則提高繪畫的效能</dd>
 <dt>{{htmlattrdef("width")}}</dt>
 <dd>在CSS 中以 pixels 表示 座標的空間<strong>寬度</strong>(預設是300)</dd>
</dl>

<h2 id="描述">描述</h2>

<h3 id="需要_&lt;canvas>_結尾">需要 <code>&lt;/canvas&gt;</code> 結尾</h3>

<p>&lt;img&gt;不同之處,<code>&lt;canvas&gt;</code>需要<code>&lt;/canvas&gt;</code> 結尾</p>

<h3 id="canvas的大小設置">canvas的大小設置</h3>

<p>canvas的大小設置可透過樣式表(stylesheet)被改變。可經由樣式修改圖像的縮放大小。</p>

<p>若呈現的效果圖似乎是扭曲變形的,可試著先修改<code>&lt;canvas&gt;</code>標籤中的<code>width</code><code>height</code>的屬性,而<strong>不建議</strong>使用css去控制。</p>

<h2 id="範例">範例</h2>

<p>將下面這條範例加到你的HTML文件。如果你的瀏覽器並不支援canvas 或不能讀取canvas 時,則會回報canvas中的訊息。若想知道更多有用的回應訊息或替代DOM的註文,可以<a href="/en-US/docs/Web/API/Canvas_API/Tutorial/Hit_regions_and_accessibility">參考更多相似的註文</a></p>

<pre class="brush: html">&lt;canvas id="canvas" width="300" height="300"&gt;
  抱歉,你的瀏覽器並不支援&lt;canvas&gt;元素
&lt;/canvas&gt;
</pre>

<p>如果你的canvas沒有使用透明度,可在&lt;canvas&gt;標籤設立<code>moz-opaque</code>屬性,提升它的繪圖效果。<code>moz-opaque</code> 尚未標準化,所以只適用在 Mozilla 的 效能引擎。</p>

<pre class="brush: html">&lt;canvas id="mycanvas" moz-opaque&gt;&lt;/canvas&gt;</pre>

<h2 id="規範">規範</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">規格</th>
   <th scope="col">狀態</th>
   <th scope="col">註解</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('HTML WHATWG', 'the-canvas-element.html#the-canvas-element', '&lt;canvas&gt;')}}</td>
   <td>{{Spec2('HTML WHATWG')}}</td>
   <td> </td>
  </tr>
  <tr>
   <td>{{SpecName('HTML5 W3C', 'the-canvas-element.html#the-canvas-element', '&lt;canvas&gt;')}}</td>
   <td>{{Spec2('HTML5 W3C')}}</td>
   <td>原始的定義</td>
  </tr>
 </tbody>
</table>

<h2 id="瀏覽器相容性">瀏覽器相容性</h2>

{{Compat("html.elements.canvas")}}

<h2 id="延伸閱讀">延伸閱讀</h2>

<ul>
 <li><a href="/en-US/docs/Web/API/Canvas_API">MDN canvas portal</a></li>
 <li><a href="/en-US/docs/Web/API/Canvas_API/Tutorial">Canvas tutorial</a></li>
 <li><a href="https://simon.html5.org/dump/html5-canvas-cheat-sheet.html">Canvas cheat sheet</a></li>
 <li><a href="/en-US/demos/tag/tech:canvas">Canvas-related demos</a></li>
 <li><a href="https://developer.apple.com/library/safari/documentation/AudioVideo/Conceptual/HTML-canvas-guide/Introduction/Introduction.html">Canvas introduction by Apple</a></li>
</ul>

<div>{{HTMLRef}}</div>