Repeat an image both horizontally and vertically:
JavaScript:
Internet Explorer 9, Firefox, Opera, Chrome, and Safari support the createPattern() method.
Note: Internet Explorer 8 and earlier versions, do not support the <canvas> element.
The createPattern() method repeats the specified element in the specified direction.
The element can be an image, video, or another <canvas> element.
The repeated element can be used to draw/fill rectangles, circles, lines etc.
JavaScript syntax: | 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 | Play it » |
repeat-x | The pattern repeats only horizontally | Play it » |
repeat-y | The pattern repeats only vertically | Play it » |
no-repeat | The pattern will be displayed only once (no repeat) | Play it » |