fillRect(100,100,100,100) The first two 100s refer to the coordinates, and the last two 100s refer to the width and height.
Today I was learning HTML5 canvas and found that the coordinates and size of fillRect were always wrong. After studying for a long time, I found that the width and height of canvas must be inline in the canvas tag. I was depressed for a long time.
Wrong way 1:
Document
<script> <br>var c = document.getElementById ('mycanvas'); <br>var ctx = c.getContext("2d"); <br>ctx.fillStyle='#f36'; <br>ctx.fillRect(100, 100, 100, 100); <br></script>
Wrong way 2:
Document < ;canvas id='mycanvas' style='width:200px;height:200px;background:yellow'>
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31