分類 | 名稱 | DOM 介面 |
---|---|---|
html | HTMLHtmlElement | |
文件資料元素 | head | HTMLHeadElement |
title | HTMLTitleElement | |
base | HTMLBaseElement | |
link | HTMLLinkElement | |
meta | HTMLMetaElement | |
style | HTMLStyleElement | |
script | HTMLScriptElement | |
noscript | HTMLElement | |
區域元素 | body | HTMLBodyElement |
section | HTMLElement | |
nav | HTMLElement | |
article | HTMLElement | |
aside | HTMLElement | |
h1 h2 h3 h4 h5 h6 | HTMLHeadingElement | |
hgroup | HTMLElement | |
header | HTMLElement | |
footer | HTMLElement | |
address | HTMLElement | |
群組元素 | p | HTMLParagraphElement |
hr | HTMLHRElement | |
pre | HTMLPreElement | |
blockquote | HTMLQuoteElement | |
ol | HTMLOListElement | |
ul | HTMLUListElement | |
li | HTMLLIElement | |
dl | HTMLDListElement | |
dt | HTMLElement | |
dd | HTMLElement | |
figure | HTMLElement | |
figcaption | HTMLElement | |
div | HTMLDivElement | |
文字階層元素 | a | HTMLAnchorElement |
em | HTMLElement | |
strong | HTMLElement | |
small | HTMLElement | |
s | HTMLElement | |
cite | HTMLElement | |
q | HTMLQuoteElement | |
dfn | HTMLElement | |
abbr | HTMLElement | |
data | HTMLDataElement | |
time | HTMLTimeElement | |
code | HTMLElement | |
var | HTMLElement | |
samp | HTMLElement | |
kbd | HTMLElement | |
sub | HTMLElement | |
sup | HTMLElement | |
i | HTMLElement | |
b | HTMLElement | |
u | HTMLElement | |
mark | HTMLElement | |
ruby | HTMLElement | |
rt | HTMLElement | |
rp | HTMLElement | |
bdi | HTMLElement | |
bdo | HTMLElement | |
span | HTMLSpanElement | |
br | HTMLBRElement | |
wbr | HTMLElement | |
編訂元素 | ins | HTMLModElement |
del | HTMLModElement | |
內嵌元素 | img | HTMLImageElement |
iframe | HTMLIFrameElement | |
embed | HTMLEmbedElement | |
object | HTMLObjectElement | |
param | HTMLParamElement | |
video | HTMLVideoElement | |
audio | HTMLAudioElement | |
source | HTMLSourceElement | |
track | HTMLTrackElement | |
canvas | HTMLCanvasElement | |
map | HTMLMapElement | |
area | HTMLAreaElement | |
applet | HTMLAppletElement | |
表格元素 | table | HTMLTableElement |
caption | HTMLTableCaptionElement | |
colgroup | HTMLTableColElement | |
col | HTMLTableColElement | |
tbody | HTMLTableSectionElement | |
thead | HTMLTableSectionElement | |
tfoot | HTMLTableSectionElement | |
tr | HTMLTableRowElement | |
td | HTMLTableDataCellElement | |
th | HTMLTableHeaderCellElement | |
表單元素 | form | HTMLFormElement |
fieldset | HTMLFieldSetElement | |
legend | HTMLLegendElement | |
label | HTMLLabelElement | |
input | HTMLInputElement | |
button | HTMLButtonElement | |
select | HTMLSelectElement | |
datalist | HTMLDataListElement | |
optgroup | HTMLOptGroupElement | |
option | HTMLOptionElement | |
textarea | HTMLTextAreaElement | |
keygen | HTMLKeygenElement | |
output | HTMLOutputElement | |
progress | HTMLProgressElement | |
meter | HTMLMeterElement | |
互動式元素 | details | HTMLDetailsElement |
summary | HTMLElement | |
command | HTMLCommandElement | |
menu | HTMLMenuElement |
其中,取得 <canvas> 的元素物件 (object) 後,利用 HTMLCanvasElement 物件的 getContext() 方法會回傳 CanvasRenderingContext2D 物件,其用於 <canvas> 的繪圖,有以下的屬性 (attribute) 與方法 (method)
類型 | 名稱 | 說明 |
---|---|---|
參考 | canvas | 對 <canvas> 物件的參考 |
狀態 | save() | 儲存目前的繪圖狀態 |
restore() | 回復 save() 所儲存的繪圖狀態 | |
變形 | scale() | 縮放圖形 |
rotate() | 旋轉圖形 | |
translate() | 位移圖形 | |
transform() | 利用矩陣使圖片變形 | |
setTransform() | 重新設置單位矩陣,然後呼叫 transform() 使圖片變形 | |
合成 | globalAlpha | 設置圖片的透明度 |
globalCompositeOperation | 設置圖形的重疊規則 | |
顏色與樣式 | strokeStyle | 設定線條顏色 |
fillStyle | 設定填滿形狀的顏色 | |
createLinearGradient() | 回傳 CanvasGradient 物件,用來設定線狀的漸層顏色 | |
createRadialGradient() | 回傳 CanvasGradient 物件,用來設定圓形的漸層顏色 | |
CanvasGradient.addColorStop() | CanvasGradient 物件設定顏色的方法 | |
createPattern() | 設定圖形的填充式樣 | |
線條樣式 | lineWidth | 設定路徑線條的寬度 |
lineCap | 設定路徑線條頂點的樣式 | |
lineJoin | 設定路徑線條相接的樣式 | |
miterLimit | 回傳路徑線條的斜接長度 | |
陰影 | shadowOffsetX | 設定文字水平方向的陰影 |
shadowOffsetY | 設定文字垂直方向的陰影 | |
shadowBlur | 設定陰影文字的模糊度 | |
shadowColor | 設定陰影文字的顏色 | |
長方形 | clearRect() | 清空指定的長方形區域 |
fillRect() | 畫出填滿顏色的長方形 | |
strokeRect() | 畫出長方形區域的外框 | |
路徑 | beginPath() | 啟動繪製路徑的程序 |
closePath() | 連結路徑的起點與終點,然後關閉繪製路徑的程序 | |
moveTo() | 移動目前繪圖路徑到指定座標 | |
lineTo() | 畫出直線到指定座標 | |
quadraticCurveTo() | 畫出二次方貝茲曲線 | |
bezierCurveTo() | 畫出三次方貝茲曲線 | |
arcTo() | 畫出弧線 | |
rect() | 畫出矩形 | |
arc() | 畫出弧線 | |
fill() | 填滿顏色 | |
stroke() | 畫出路徑筆劃的顏色 | |
drawSystemFocusRing() | ||
drawCustomFocusRing() | ||
scrollPathIntoView() | ||
clip() | 剪裁指定的路徑或區域 | |
isPointInPath() | ||
文字 | font | 設定文字字型 |
textAlign | 設定文字水平對齊方式 | |
textBaseline | 設定文字基線對齊方式 | |
fillText() | 畫出文字 | |
strokeText() | 畫出鏤空字型 | |
measureText() | 回傳記錄文字度量值的 TextMetrics 物件 | |
圖檔 | drawImage() | 畫出圖片檔案 |
畫素處理 | createImageData() | 回傳 ImageData 物件,用以對圖像進行畫素等級的處理動作 |
getImageData() | 回傳 ImageData 物件,用以對圖像進行畫素等級的處理動作 | |
putImageData() | 將 ImageData 物件放回 CanvasRenderingContext2D 之中 |
茲舉一例如下
function run() { var d = document.getElementsByTagName("canvas"); var c = d[0].getContext("2d"); c.font = "20px Courier"; var t = "There is no spoon."; c.strokeText(t, 10, 30); } /* 《程式語言教學誌》的範例程式 http://pydoing.blogspot.com/ 檔名:htmldemo111.js 功能:示範 JavaScript 程式 作者:張凱慶 時間:西元 2011 年 8 月 */
此例用 document 物件的 getElementsByTagName() 方法,取得標籤名稱為 canvas 的 HTMLCollection 物件,文件的第一個 <canvas> 元素亦即該 HTMLCollection 索引值為 0 的物件
var d = document.getElementsByTagName("canvas"); var c = d[0].getContext("2d");
接著設定文字字型、文字顏色,最後呼叫 strokeText() 畫出文字外框
c.font = "20px Courier"; var t = "There is no spoon."; c.strokeText(t, 10, 30);
我們以下面的 HTML 文件載入
<!DOCTYPE html> <html> <head> <title>HTML DOM DEMO</title> <script src="htmldemo111.js" type="text/javascript"></script> </head> <body onload="run();"> <canvas id="demo" width="250" height="180"></canvas> </html> <!-- 《程式語言教學誌》的範例程式 http://pydoing.blogspot.com/ 檔名:htmldemo111.html 功能:示範 JavaScript 程式 作者:張凱慶 時間:西元 2011 年 8 月 -->
瀏覽器 (browser) 開啟如下
中英文術語對照 | |
---|---|
元素 | element |
物件 | object |
屬性 | attribute |
方法 | method |
瀏覽器 | browser |
您可以繼續參考
HTML 5 範例
HTML 元素物件
- 根元素
- 文件資料元素
- <head> (HTMLHeadElement)
- <title> (HTMLTitleElement)
- <base> (HTMLBaseElement)
- <link> (HTMLLinkElement)
- <meta> (HTMLMetaElement)
- <style> (HTMLStyleElement)
- <script> (HTMLScriptElement)
- <noscript> (HTMLElement)
- 文件區域元素
- <body> (HTMLBodyElement)
- <section> (HTMLElement)
- <nav> (HTMLElement)
- <article> (HTMLElement)
- <aside> (HTMLElement)
- <h1> <h2> <h3> <h4> <h5> <h6> (HTMLHeadingElement)
- <hgroup> (HTMLElement)
- <header> (HTMLElement)
- <footer> (HTMLElement)
- <address> (HTMLElement)
- 群組元素
- <p> (HTMLParagraphElement)
- <hr> (HTMLHRElement)
- <pre> (HTMLPreElement)
- <blockquote> (HTMLQuoteElement)
- <ol> (HTMLOListElement)
- <ul> (HTMLUListElement)
- <li> (HTMLLIElement)
- <dl> (HTMLDListElement)
- <dt> (HTMLElement)
- <dd> (HTMLElement)
- <figure> (HTMLElement)
- <figcaption> (HTMLElement)
- <div> (HTMLDivElement)
- 文字層級元素
- <a> (HTMLAnchorElement)
- <em> (HTMLElement)
- <strong> (HTMLElement)
- <small> (HTMLElement)
- <s> (HTMLElement)
- <cite> (HTMLElement)
- <q> (HTMLQuoteElement)
- <dfn> (HTMLElement)
- <abbr> (HTMLElement)
- <data> (HTMLDataElement)
- <time> (HTMLTimeElement)
- <code> (HTMLElement)
- <var> (HTMLElement)
- <samp> (HTMLElement)
- <kbd> (HTMLElement)
- <sub> (HTMLElement)
- <sup> (HTMLElement)
- <i> (HTMLElement)
- <b> (HTMLElement)
- <u> (HTMLElement)
- <mark> (HTMLElement)
- <ruby> (HTMLElement)
- <rt> (HTMLElement)
- <rp> (HTMLElement)
- <bdi> (HTMLElement)
- <bdo> (HTMLElement)
- <span> (HTMLSpanElement)
- <br / > (HTMLBRElement)
- <wbr> (HTMLElement)
- 編修記錄元素
- 內嵌媒體元素
- <img> (HTMLImageElement)
- <iframe> (HTMLIFrameElement)
- <embed> (HTMLEmbedElement)
- <object> (HTMLObjectElement)
- <param> (HTMLParamElement)
- <video> (HTMLVideoElement)
- <audio> (HTMLAudioElement)
- <source> (HTMLSourceElement)
- <track> (HTMLTrackElement)
- <canvas> (HTMLCanvasElement)
- CanvasRenderingContext2D
- CanvasRenderingContext2D.canvas
- CanvasRenderingContext2D.save()
- CanvasRenderingContext2D.restore()
- CanvasRenderingContext2D.scale()
- CanvasRenderingContext2D.rotate()
- CanvasRenderingContext2D.translate()
- CanvasRenderingContext2D.transform()
- CanvasRenderingContext2D.setTransform()
- CanvasRenderingContext2D.globalAlpha
- CanvasRenderingContext2D.globalCompositeOperation
- CanvasRenderingContext2D.strokeStyle
- CanvasRenderingContext2D.fillStyle
- CanvasRenderingContext2D.createLinearGradient()
- CanvasRenderingContext2D.createRadialGradient()
- CanvasGradient 物件
- CanvasRenderingContext2D.createPattern()
- CanvasRenderingContext2D.lineWidth
- CanvasRenderingContext2D.lineCap
- CanvasRenderingContext2D.lineJoin
- CanvasRenderingContext2D.miterLimit
- CanvasRenderingContext2D.shadowOffsetX
- CanvasRenderingContext2D.shadowOffsetY
- CanvasRenderingContext2D.shadowBlur
- CanvasRenderingContext2D.shadowColor
- CanvasRenderingContext2D.clearRect()
- CanvasRenderingContext2D.fillRect()
- CanvasRenderingContext2D.strokeRect()
- CanvasRenderingContext2D.beginPath()
- CanvasRenderingContext2D.closePath()
- CanvasRenderingContext2D.moveTo()
- CanvasRenderingContext2D.lineTo()
- CanvasRenderingContext2D.quadraticCurveTo()
- CanvasRenderingContext2D.bezierCurveTo()
- CanvasRenderingContext2D.arcTo()
- CanvasRenderingContext2D.rect()
- CanvasRenderingContext2D.arc()
- CanvasRenderingContext2D.fill()
- CanvasRenderingContext2D.stroke()
- CanvasRenderingContext2D.drawSystemFocusRing()
- CanvasRenderingContext2D.drawCustomFocusRing()
- CanvasRenderingContext2D.scrollPathIntoView()
- CanvasRenderingContext2D.clip()
- CanvasRenderingContext2D.isPointInPath()
- CanvasRenderingContext2D.font
- CanvasRenderingContext2D.textAlign
- CanvasRenderingContext2D.textBaseline
- CanvasRenderingContext2D.fillText()
- CanvasRenderingContext2D.strokeText()
- CanvasRenderingContext2D.measureText()
- CanvasRenderingContext2D.drawImage()
- CanvasRenderingContext2D.createImageData()
- CanvasRenderingContext2D.getImageData()
- CanvasRenderingContext2D.putImageData()
- <map> (HTMLMapElement)
- <area> (HTMLAreaElement)
- <applet> (HTMLAppletElement)
- 表格元素
- <table> (HTMLTableElement)
- <caption> (HTMLTableCaptionElement)
- <colgroup> (HTMLTableColElement)
- <col> (HTMLTableColElement)
- <tbody> (HTMLTableSectionElement)
- <thead> (HTMLTableSectionElement)
- <tfoot> (HTMLTableSectionElement)
- <tr> (HTMLTableRowElement)
- <td> (HTMLTableDataCellElement)
- <th> (HTMLTableHeaderCellElement)
- 表單元素
- <form> (HTMLFormElement)
- <fieldset> (HTMLFieldSetElement)
- <legend> (HTMLLegendElement)
- <label> (HTMLLabelElement)
- <input> (HTMLInputElement)
- <button> (HTMLButtonElement)
- <select> (HTMLSelectElement)
- <datalist> (HTMLDataListElement)
- <optgroup> (HTMLOptGroupElement)
- <option> (HTMLOptionElement)
- <textarea> (HTMLTextAreaElement)
- <keygen> (HTMLKeygenElement)
- <output> (HTMLOutputElement)
- <progress> (HTMLProgressElement)
- <meter> (HTMLMeterElement)
- 互動式元素
相關目錄
HTML DOM 快速導覽
JavaScript 教材
首頁
參考資料
https://developer.mozilla.org/en/Gecko_DOM_Reference
http://www.whatwg.org/specs/web-apps/current-work/multipage/semantics.html#semantics
沒有留言:
張貼留言