html <canvas> 标签通过 JavaScript 来绘制图形,比如图表和其他图像
<canvas> 标签只是图形容器,必须使用脚本来绘制图形
<canvas> 元素中的任何文本将会被显示在不支持 <canvas> 的浏览器中
属性
属性 | 值 | 描述 |
---|---|---|
height |
pixels | 设置画布的高度 |
width |
pixels | 设置画布的宽度 |
范例
通过 <canvas> 元素来显示一个红色的矩形
<canvas id="myCanvas"></canvas> <script>var canvas=document.getElementById('myCanvas');var ctx=canvas.getContext('2d'); ctx.fillStyle='#FF0000'; ctx.fillRect(0,80,100); </script>