xuan52rock

clearRect清除html5画布

html5 canvas 清除可以使用clearRect() 方法

clearRect() 方法的作用是清空给定矩形内的指定像素。
JavaScript 语法:
context.clearRect(x,y,width,height);

x 要清除的矩形左上角的 x 坐标
y 要清除的矩形左上角的 y 坐标
width 要清除的矩形的宽度,以像素计
height 要清除的矩形的高度,以像素计


<!DOCTYPE html>
<html>
<body>

<canvas id="myCanvas_keleyi_com" width="300" height="150" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.
</canvas>

<script>

var c=document.getElementById("myCanvas_ke"+"leyi_com");
var ctx=c.getContext("2d");
ctx.fillStyle="red";
ctx.fillRect(0,0,300,150);
ctx.clearRect(20,20,100,50);

</script>

</body>
</html>

分类:

技术点:

相关文章:

  • 2021-05-28
  • 2021-12-05
  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
  • 2021-11-20
  • 2021-12-03
  • 2021-11-07
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-20
  • 2021-09-14
  • 2021-12-05
  • 2021-12-10
  • 2022-01-13
相关资源
相似解决方案