Canvas createPattern() Method
Definition and Usage
createPattern()
Ang paraan ay gumagamit ng pinagmumulan sa tinukoy na direksyon.
Ang elementong maaaring maging imahen, video, o iba pang <canvas> element.
Ang pinagmumulan ng pagpapatuloy ay maaaring gamitin sa pagpipinta o pagpupunan ng rectangle, circle o linya at iba pa.
Sample
Ginamit na imahen:

Ipalit sa horizontal at vertical na direksyon ang imahen:
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();
Syntax
context.createPattern(image,"repeat|repeat-x|repeat-y|no-repeat");
Parameter value
Parameter | Description |
---|---|
image | Tukuyin ang imaheng gamit, canvas o video element. |
repeat | Default. Ang pattern ay gumagamit sa horizontal at vertical na direksyon. |
repeat-x | Ang pattern ay gumagamit lamang sa horizontal na direksyon. |
repeat-y | 该模式只在垂直方向重复。 |
no-repeat | 该模式只显示一次(不重复)。 |
浏览器支持
表中的数字注明了首个完全支持该属性的浏览器版本。
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
4.0 | 9.0 | 3.6 | 4.0 | 10.1 |
注释:Internet Explorer 8 以及更早的版本不支持 <canvas> 元素。