150*100 ピクセルの矩形を描画します:
JavaScript:
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.strokeRect(20,20,150,100);
Try it Yourself ❯
表中の数字は、メソッドを完全にサポートした最初のブラウザ・バージョンを指定しています。
メソッド | |||||
---|---|---|---|---|---|
strokeRect() | Yes | 9.0 | Yes | Yes | Yes |
strokeRect() メソッドは、矩形(塗りなし)を描画します。描画する線のデフォルト色は黒です。
チップ: 線のスタイルに、色、グラデーション、パターンを設定するには、 strokeStyle プロパティを使用します。
JavaScript 構文: | context.strokeRect(x,y,width,height); |
---|
パラメータ | 説明 | Play it |
---|---|---|
x | 矩形の左上隅の x 座標 | Play it ❯ |
y | 矩形の左上隅の y 座標 | Play it ❯ |
width | 矩形の幅(ピクセル単位) | Play it ❯ |
height | 矩形の高さ(ピクセル単位) | Play it ❯ |