HTML5Canvas画布之清空画布

<!DOCTYPE html>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Canvas练习</title>

<script type="text/javascript">

   function clearMap(){

      context.clearRect(0,0,300,200);

   }

</script>

</head>

<body>

  <canvas id="myCanvas" style="border:1px solid" width="300" height="150">

     您的浏览器不支持canvas元素,请更新或更换您的浏览器。

  </canvas>

  <script type="text/javascript">

     var c=document.getElementById("myCanvas");

var context=c.getContext("2d");

context.fillStyle="red";

context.beginPath();

context.arc(200,150,100,-Math.PI*1/6,-Math.PI*5/6,true);

context.stroke();

  </script><br>

  <input name="" type="button" value="清空画布" onClick="clearMap();">

</body>

</html>

猜你喜欢

转载自qiuhaodong.iteye.com/blog/2289410