HTMLキャンバスcreatePattern()メソッド
使用する画像:
例
水平方向と垂直方向の両方で画像を繰り返します。
JavaScript:
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
var img = document.getElementById("lamp");
var pat = ctx.createPattern(img, "repeat");
ctx.rect(0, 0, 150, 100);
ctx.fillStyle = pat;
ctx.fill();
ブラウザのサポート
表の数字は、このメソッドを完全にサポートする最初のブラウザバージョンを示しています。
Method | |||||
---|---|---|---|---|---|
createPattern() | Yes | 9.0 | Yes | Yes | Yes |
定義と使用法
createPattern()メソッドは、指定された要素を指定された方向に繰り返します。
要素は、画像、ビデオ、または別の<canvas>要素にすることができます。
繰り返される要素は、長方形、円、線などを描画/塗りつぶすために使用できます。
JavaScript構文: | context .createPattern(image、 "repeat | repeat-x | repeat-y | no-repeat"); |
---|
パラメータ値
Parameter | Description | Play it |
---|---|---|
image | Specifies the image, canvas, or video element of the pattern to use | |
repeat | Default. The pattern repeats both horizontally and vertically | |
repeat-x | The pattern repeats only horizontally | |
repeat-y | The pattern repeats only vertically | |
no-repeat | The pattern will be displayed only once (no repeat) |
❮HTMLキャンバスリファレンス