运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,暗色/亮色
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>HTML5 Canvas - strokeRect()</h1> <canvas id="myCanvas" width="300" height="150" style="border:1px solid black"> Sorry, your browser does not support canvas. </canvas> <script> const canvas = document.getElementById("myCanvas"); const ctx = canvas.getContext("2d"); // Red rectangle ctx.lineWidth = "6"; ctx.strokeStyle = "red"; ctx.strokeRect(5, 5, 290, 140); // Green rectangle ctx.lineWidth = "4"; ctx.strokeStyle = "green"; ctx.strokeRect(30, 30, 50, 50); // Blue rectangle ctx.lineWidth = "10"; ctx.strokeStyle = "blue"; ctx.strokeRect(50, 50, 150, 80); </script> </body> </html>