-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path9.模式.html
60 lines (50 loc) · 1.26 KB
/
9.模式.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<style type="text/css">
canvas{
border:1px solid black;
}
#kno{
width: 500px;
height: auto;
float: left;
font-size: 18px;
}
img{
width: 200px;
height: 200px;
}
</style>
<script type="text/javascript">
window.onload=function(){
//获取元素
var canvas01=document.getElementById("canvas01");
//确定浏览器支持<canvas>元素
if(canvas01.getContext){
//取得上2d下文
var context=canvas01.getContext("2d");
var image=document.images[0],
pattern=context.createPattern(image,"repeat");
//绘制矩形
context.fillStyle=pattern;
context.fillRect(10,10,180,180);
}
}
</script>
<body>
<!-- canvas元素-->
<canvas id="canvas01" width="200px" height="200px"></canvas>
<!-- 图片资源引入 -->
<img src="./img/img02.png" />
<!-- 知识点和问题汇总 -->
<div id="kno">
<b>知识点:</b> <br/>
<strong>1.</strong>createPattern第一个参数可以是:html<img>元素、<video>元素或另一个<canvas>
。第二个参数和css的background-repeat相同,有repeat/repeat-x/repeat-y/no-repeat <br/>
</div>
</body>
</html>