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
-
2025-02-26 03:58:14
-
2025-02-26 03:38:10
-
2025-02-26 03:17:10
-
2025-02-26 02:49:09
-
2025-02-26 01:08:13
-
2025-02-26 00:46:10
-
2025-02-25 23:42:08
-
2025-02-25 22:50:13
-
2025-02-25 21:54:11
-
2025-02-25 20:45:11
Latest Issues
-
2025-03-18 14:18:31
-
2025-03-18 14:17:34
-
2025-03-18 14:16:27
-
2025-03-18 14:07:32
-
2025-03-18 14:06:34