HTML 5 <canvas> 标签

定义和用法

<canvas> 标签定义图形,比如图表和其他图像。

HTML 4.01 与 HTML 5 之间的差异

<canvas> 标签是 HTML 5 中的新标签。

示例

<script type="text/javascript">
function drawCanvas()
{
var canvas=document.getElementById('myCanvas');
var ctx=canvas.getContext('2d');
ctx.fillStyle='#FF0000';
ctx.fillRect(0,0,80,100);
}
</script>
...


<canvas id="myCanvas">
your browser does not support the canvas tag
</canvas>

属性

属性 描述
heightpixels设置 canvas 的高度。
widthpixels设置 canvas 的宽度。

标准属性

class, contenteditable, contextmenu, dir, draggable, id, irrelevant, lang, ref, registrationmark, tabindex, template, title

事件属性

onabort, onbeforeunload, onblur, onchange, onclick, oncontextmenu, ondblclick, ondrag, ondragend, ondragenter, ondragleave, ondragover, ondragstart, ondrop, onerror, onfocus, onkeydown, onkeypress, onkeyup, onload, onmessage, onmousedown, onmousemove, onmouseover, onmouseout, onmouseup, onmousewheel, onresize, onscroll, onselect, onsubmit, onunload