运行 ❯
获取您
自己
的网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>globalCompositeOperation = "destination-atop"</h1> <p>The "destination-atop" value will keep the existing content where it overlaps the new shape. The new shape is drawn behind 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 = "destination-atop"; // 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>