HTML5 canvas学习的实例介绍
程序员文章站
2022-04-25 18:34:35
...
1.HTML5中的Canvas标签的创建
window.onload = function(){ createCanvas(); } function createCanvas(){ var canvas_width= 200, canvas_height = 200; document.body.innerHTML = "<canvas id=\"canvas\" width=\""+canvas_width+"\" height=\""+canvas_height+"\"></canvas>"; }
2.HTML5Canvas标签绘制图形
var canvas_width= 500, canvas_height = 500;var mycanvas, context; window.onload = function(){ createCanvas(); drawRect(); } function createCanvas(){ document.body.innerHTML = "<canvas id=\"mycanvas\" width=\""+canvas_width+"\" height=\""+canvas_height+"\"></canvas>"; mycanvas = document.getElementById("mycanvas"); context = mycanvas.getContext("2d"); } function drawRect(){ context.fillStyle ="#FF0000"; //context.rotate(45);//旋转45度 //context.translate(200,200);//移动 //context.scale(2,0.5);//缩放 context.fillRect(0,0,200,200); }
3.HTML5Canvas标签绘制图片
var canvas_width= 500, canvas_height = 500;var mycanvas, context; window.onload = function(){ createCanvas(); drawImage(); } function createCanvas(){ document.body.innerHTML = "<canvas id=\"mycanvas\" width=\""+canvas_width+"\" height=\""+canvas_height+"\"></canvas>"; mycanvas = document.getElementById("mycanvas"); context = mycanvas.getContext("2d"); } function drawImage(){ var img = new Image(); img.onload = function(){ context.drawImage(img,0,0); } img.src = "1.png"; }
以上就是HTML5 canvas学习的实例介绍的详细内容,更多请关注其它相关文章!
上一篇: 详细介绍几种JavaScript编码规范(详细教程)
下一篇: Python判断操作系统类型代码分享
推荐阅读
-
listview改变选中行的字体颜色实例介绍
-
值得收藏的HTML5资源(学习html5的朋友可以收藏下)
-
html5中canvas学习笔记2-判断浏览器是否支持canvas
-
html5 canvas-1.canvas介绍(hello canvas)
-
html5 Canvas画图教程(1)—画图的基本常识
-
HTML5 实现一个访问本地文件的实例
-
网易微博Web App用HTML5开发的过程介绍
-
html5 Canvas画图教程(2)—画直线与设置线条的样式如颜色/端点/交汇点
-
html5 canvas绘制矩形和圆形的实例代码
-
用html5的canvas和JavaScript创建一个绘图程序的简单实例