html5圖形的保存與huif


<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 οnlοad="draw('canvas')">
<canvas id="canvas" width="600" height="600" style="border:1px solid blue;"></canvas>
</body>

</html>


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章