HTMLキャンバスfillRect()メソッド
例
塗りつぶされた150 * 100ピクセルの長方形を描画します。
JavaScript:
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.fillRect(20, 20, 150, 100);
ブラウザのサポート
表の数字は、このメソッドを完全にサポートする最初のブラウザバージョンを示しています。
Method | |||||
---|---|---|---|---|---|
fillRect() | Yes | 9.0 | Yes | Yes | Yes |
定義と使用法
fillRect()メソッドは、「塗りつぶされた」長方形を描画します。塗りつぶしのデフォルトの色は黒です。
ヒント:fillStyleプロパティを使用して、図面の塗りつぶしに使用する色、グラデーション、またはパターンを設定します。
JavaScript構文: | context .fillRect(x、y、width、height); |
---|
パラメータ値
Parameter | Description | Play it |
---|---|---|
x | The x-coordinate of the upper-left corner of the rectangle | |
y | The y-coordinate of the upper-left corner of the rectangle | |
width | The width of the rectangle, in pixels | |
height | The height of the rectangle, in pixels |
❮HTMLキャンバスリファレンス