canvas-2drawRectFun.html
2015-11-19 17:27
423 查看
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <canvas id="canvas" style="margin:0 auto;"> The current browser does not support Canvas, can replace the browser a try! </canvas> <script> // 绘制矩形 function drawRect(ctx,x,y,width,height,borderWidth,borderColor,fillColor){ ctx.beginPath(); ctx.moveTo(x,y); ctx.lineTo(x+width,y); ctx.lineTo(x+width,y+height); ctx.lineTo(x,y+height); ctx.closePath(); ctx.lineWidth = borderWidth; ctx.strokeStyle = borderColor; ctx.fillStyle = fillColor; ctx.fill(); ctx.stroke(); } window.onload = function(){ var canvas = document.getElementById('canvas'); canvas.width = 1024; canvas.height = 768; if(canvas.getContext('2d')){ var context = canvas.getContext('2d'); drawRect(context,100,100,400,400,10,"blue","yellow") }else{ alert('当前游览器不支持Canvas,请更换游览器后再试!'); } } </script> </body> </html>
相关文章推荐
- canvas-0trasform.html
- canvas-0translate.html
- canvas-0scale.html
- canvas-tangram.html
- Canvas-line.html
- HTML\Script 去除关键字
- canvas-arc.html
- html弹出div弹窗
- 在Word指定位置插入富文本域值(html文本)
- 实现html页面的参数传递
- HTML常用标签大全及html标签的特点
- HTML中网页超链接设计
- html控件隐藏几种方法,占位隐藏
- web -- HTML 字符实体
- 南大软院大神养成计划——html 的简单介绍及一些标签的使用
- html弹出层
- html 如何获取表格中所选行的一行数据,并赋值到对应的TEXT里面?
- html页面通过特殊链接:打电话,发短信,发邮件详细教程
- HTML常用标签
- 南昌大学大神养成计划-第一课《html》