获取您自己的 网站 Result Size: 625 x 664
x
 
<!DOCTYPE html>
<html>
<body>
<h1>globalCompositeOperation = "source-out"</h1>
<p>The "source-out" value will draw new shapes only where it does not overlap the existing content.</p>
<canvas id="myCanvas" width="300" height="150" style="border:1px solid grey">
Sorry, your browser does not support canvas.
</canvas>
<script>
const canvas = document.getElementById("myCanvas");
const ctx = canvas.getContext("2d");
// Set type of compositing
ctx.globalCompositeOperation = "source-out";
// Draw two overlapping rectangles  
ctx.fillStyle = "blue";
ctx.fillRect(10, 10, 100, 100);
ctx.fillStyle = "red";
ctx.fillRect(40, 40, 100, 100);
</script>
</body>
</html>