We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Learn more about funding links in repositories.
Report abuse
There was an error while loading. Please reload this page.
第123天 使用canvas画出一个矩形
<canvas width="1000" height="500" id="cvs"></canvas> ... <script> document.getElementById('cvs').getContext('2d').fillRect(100, 100, 800, 300) </script>
<canvas id="canvas" width="300" height="300"></canvas> <script> var canvas = document.getElementById("canvas") if(canvas.getContext){ var ctx = canvas.getContext("2d") ctx.fillStyle="rgb(200,0,0)" ctx.fillRect(10,10,60,30) } </script>
<script> var canvas = document.getElementById('canvas'); var ctx = canvas.getContext('2d'); ctx.beginPath(); ctx.rect(200,200,100,100); ctx.closePath(); ctx.stroke(); </script>
Canvas 中内置的图形只有矩形,其余图形都需要通过路径来进行绘制。可以使用 canvas 的 fillRect 方法来绘制矩形。
canvas
fillRect
参考文档:MDN Canvas 教程
Activity
ghost commentedon Aug 17, 2019
LiunanYang commentedon Aug 17, 2019
Joan428 commentedon Aug 17, 2019
<script> var canvas = document.getElementById('canvas'); var ctx = canvas.getContext('2d'); ctx.beginPath(); ctx.rect(200,200,100,100); ctx.closePath(); ctx.stroke(); </script>
Konata9 commentedon Aug 19, 2019
Canvas 中内置的图形只有矩形,其余图形都需要通过路径来进行绘制。可以使用
canvas
的fillRect
方法来绘制矩形。参考文档:MDN Canvas 教程