html5 canvas fillRect坐标和大小的问题解决方法

解决方法:canvas的宽度和高度必须内联在canvas标签中。

错误示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
#mycanvas{
width: 200px;
height: 200px;
background: yellow;
}
</style>
</head>
<body>
<canvas id='mycanvas' ></canvas>
</body>
</html>

正确示例:

1
<canvas id='mycanvas' width='200px' height='200px' style='background:yellow'></canvas>

评论区