您的位置:首页 > Web前端 > JavaScript

每天一个JavaScript实例-canvas画图

2014-11-03 14:16 751 查看
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>每天一个JavaScript实例-canvas画图</title>
<style>
.canvas{
width:600px;
height:500px;
}
</style>

<script>
window.onload = function(){
var imgcanvas = document.getElementById("imgcanvas");
if(imgcanvas.getContext){
var ctx = imgcanvas.getContext('2d');
ctx.fillStyle="rgba(255,0,0,.1)";
ctx.strokeStyle = "#000";
//第一个
ctx.fillRect(0,0,100,100);
ctx.strokeRect(0,0,100,100);
//第二个
ctx.fillRect(50,50,100,200);

//第三个
ctx.strokeRect(80,130,200,100);
}
}
</script>

</head>

<body>

<canvas class="canvas" id = "imgcanvas">
<p>画布</p>

</canvas>

</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: