html5图形的保存与huif

来源:互联网 发布:淘宝联盟发送朋友圈 编辑:程序博客网 时间:2024/06/11 16:21
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>图形的保存与恢复</title>
<script>
function draw(id){
var c=document.getElementById(id);
if(c==null)
return false;
var cxt=c.getContext("2d");
   cxt.fillStyle="yellow";
   cxt.save();
   cxt.fillRect(50,50,100,100);
   cxt.fillStyle="aqua";
   cxt.save();
   cxt.fillRect(200,50,100,100);
   cxt.restore();//撤销操作
   cxt.fillRect(350,50,100,100);
   cxt.restore();
   cxt.fillRect(50,200,100,100);
}
</script>
</head>
<body onload="draw('canvas')">
<canvas id="canvas" width="600" height="600" style="border:1px solid blue;"></canvas>
</body>

</html>


0 0