横方向と縦方向の両方向に画像を繰り返します
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();
Try it Yourself ❯
表中の数字は、メソッドを完全にサポートした最初のブラウザ・バージョンを指定しています。
メソッド | |||||
---|---|---|---|---|---|
createPattern() | Yes | 9.0 | Yes | Yes | Yes |
createPattern() メソッドは、指定した方向に指定した要素を繰り返します。
要素には、画像、ビデオ、または他の <canvas> 要素を使用することができます。
要素を繰り返して、矩形、円、線などを描画/塗りつぶしに使用することができます。
JavaScript 構文: | context.createPattern(image,"repeat|repeat-x|repeat-y|no-repeat"); |
---|
パラメータ | 説明 | Play it |
---|---|---|
image | 使用するパターンの、画像、キャンバス、ビデオ要素を指定します | |
repeat | デフォルト。横・縦両方向に繰り返すパターン | Play it ❯ |
repeat-x | pattern repeats only horizontally | Play it ❯ |
repeat-y | pattern repeats only vertically | Play it ❯ |
no-repeat | pattern will be displayed only once (no repeat) | Play it ❯ |