作者:巢i仔 | 来源:互联网 | 2022-09-25 08:09
1.HTML5中的Canvas标签的创建window.onloadfunction(){createCanvas();}functioncreateCanvas(){varcanvas_width200,canvas_height200;document.body.innerHTML"<canvasid\"canvas\"
1.
HTML5中的Canvas标签的创建window.Onload= function(){
createCanvas();
} function createCanvas(){ var canvas_width= 200, canvas_height = 200;
document.body.innerHTML = "";
}
2.HTML5Canvas标签绘制图形
var canvas_width= 500, canvas_height = 500;var mycanvas, context;
window.Onload= function(){
createCanvas();
drawRect();
} function createCanvas(){
document.body.innerHTML = "";
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 = "";
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学习的实例介绍的详细内容,更多请关注其它相关文章!