html5-canvas绘制矩形的代码 |
发布时间: 2012/8/20 18:07:27 |
html5-canvas绘制矩形的代码,代码如下所示: 计算机爱好者www.boydavid.com <!DOCTYPE html> <head> <title>canvas绘制矩形</title> </head> <script> function draw(id){
var canvas=document.getElementById(id); if(canvas==null){
return false;
}
var context=canvas.getContext('2d');
context.fillStyle='#eeeeff';
context.fillRect(0,0,400,300);
context.fillStyle='red'; context.strokeStyle='blue';
context.lineWidth=10;
context.fillRect(50,50,100,100); 电脑软件www.boydavid.com context.strokeRect(50,50,100,100);
context.fillStyle='#f60';
context.strokeStyle='#ccc'; 电脑知识www.boydavid.com context.lineWidth=5; 电脑维护www.boydavid.com context.fillRect(200,200,100,100);
context.strokeRect(150,150,100,100); 计算机学习网站www.boydavid.com }
</script>
<body onload="draw('canvas')"> 电脑知识www.boydavid.com <h1>canvas元素绘制矩形</h1> <canvas id="canvas" width="400" height="300" />
</body> 电 本文出自:亿恩科技【www.enkj.com】 |