HTML教程
HTML5教程
HTML参考手册

HTML canvas createPattern() 方法

Lamp
在水平和垂直方向重复图像:
您的浏览器不支持HTML5 canvas标签.
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();

浏览器支持

Internet Explorer Firefox Opera Google Chrome Safari
Internet Explorer 9、Firefox、Opera、Chrome 和 Safari 支持 createPattern() 方法。
注意:Internet Explorer 8 及之前的版本不支持 <canvas> 元素。

定义和用法

createPattern() 方法在指定的方向内重复指定的元素。
元素可以是图片、视频,或者其他 <canvas> 元素。
JavaScript 语法: context.createPattern(image,"repeat|repeat-x|repeat-y|no-repeat");

参数值

参数 描述
image 规定要使用的模式的图片、画布或视频元素。  
repeat 默认。该模式在水平和垂直方向重复。
repeat-x 该模式只在水平方向重复。
repeat-y 该模式只在垂直方向重复。
no-repeat 该模式只显示一次(不重复)。
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4