Metoda HTML canvas createPattern ()
HTML Instrukcja płótno referencyjny
Obrazy wykorzystane:
Przykłady
Powtarzanie obrazu w pionie i poziomie:
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();
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();
Spróbuj »
Pomoc Browser
Internet Explorer 9, Firefox, Opera, Chrome i Safari wsparcie createPattern metoda ().
Uwaga: 8 i wcześniejsze wersje programu Internet Explorer nie obsługuje <canvas> elementu.
Definicja i Wykorzystanie
Metoda createPattern () powtarza określonego elementu w określonym kierunku.
Elementy mogą być zdjęcia, filmy lub inne <canvas> elementu.
Być powtarzany element może być użyty do rysowania / wypełnić prostokąt, okrąg, linię lub tym podobne.
Składnia JavaScript: | Kontekst .createPattern (image "repeat |repeat-x | repeat-y | no-repeat"); |
---|
parametr Wartość
参数 | 描述 | |
---|---|---|
image | 规定要使用的模式的图片、画布或视频元素。 | |
repeat | 默认。该模式在水平和垂直方向重复。 | |
repeat-x | 该模式只在水平方向重复。 | |
repeat-y | 该模式只在垂直方向重复。 | |
no-repeat | 该模式只显示一次(不重复)。 |
HTML Instrukcja płótno referencyjny