运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
转到 Spaces
<!DOCTYPE html> <html> <body> <h1>HTML5 Canvas shadowOffsetX</h1> <canvas id="myCanvas" width="450" 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"); // Shadowcolor ctx.shadowColor = "lightblue"; ctx.fillStyle = "blue"; // rectangle 1 ctx.shadowOffsetX = 5; ctx.fillRect(20, 20, 100, 100); // rectangle 2 ctx.shadowOffsetX = 15; ctx.fillRect(170, 20, 100, 100); // rectangle 3 ctx.shadowOffsetX = -10; ctx.fillRect(320, 20, 100, 100); </script> </body> </html>