HTML canvas fillRect () method
Examples
Draw a filled rectangle 150 * 100 pixels:
JavaScript:
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.fillRect(20,20,150,100);
var ctx=c.getContext("2d");
ctx.fillRect(20,20,150,100);
try it"
Browser Support
Internet Explorer 9, Firefox, Opera, Chrome and Safari support fillRect () method.
Note: 8 and earlier versions of Internet Explorer do not support the <canvas> element.
Definition and Usage
fillRect () method to draw "filled" rectangle. The default fill color is black.
Tip: Use fillStyle property to set the fill color for drawing, gradient, or pattern.
JavaScript syntax: | context .fillRect (x, y, width, height); |
---|
Parameter Value
参数 | 描述 |
---|---|
x | 矩形左上角的 x 坐标。 |
y | 矩形左上角的 y 坐标。 |
width | 矩形的宽度,以像素计。 |
height | 矩形的高度,以像素计。 |
HTML canvas Reference Manual