-
Notifications
You must be signed in to change notification settings - Fork 0
/
7.阴影.html
71 lines (61 loc) · 2.08 KB
/
7.阴影.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
61
62
63
64
65
66
67
68
69
70
71
<!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;
}
</style>
<script type="text/javascript">
window.onload=function(){
//获取元素
var canvas01=document.getElementById("canvas01");
//确定浏览器支持<canvas>元素
if(canvas01.getContext){
//取得上2d下文
var context=canvas01.getContext("2d");
//设置阴影的属性
//阴影颜色
context.shadowColor="rgba(0,0,0,0.5)";
//模糊像素数
context.shadowBlur=4;
//x轴方向的阴影偏差数
context.shadowOffsetX=5;
//y轴方向的阴影偏差数
context.shadowOffsetY=5;
//绘制红色矩形
context.fillStyle="red";
context.fillRect(10,10,100,100);
//绘制蓝色矩形
context.fillStyle="rgba(0,0,255,0.5)";
context.fillRect(50,50,100,100);
}
}
</script>
<body>
<!-- canvas元素-->
<canvas id="canvas01" width="200px" height="200px"></canvas>
<canvas id="canvas02" width="200px" height="200px"></canvas>
<canvas id="canvas03" width="200px" height="200px"></canvas>
<!-- 知识点和问题汇总 -->
<div id="kno">
<b>知识点:</b> <br/>
<strong>1.</strong>绘制文本的方法:fillText()和strokeText(),一般用fillText() <br/>
<strong>2.</strong>上述方法的属性:font、textAlign、textBaseline <br/>
<strong>3.</strong>fillText(文本字符串,x,y,最大像素宽度(可选)) <br/>
<strong>4.</strong>context.font="样式 大小 字体 "; <br/>
<strong>5.</strong>textAlign:center、start、end <br/>
<strong>6.</strong>textBaseline:middle、top、bottom <br/>
<strong>7.</strong>context.measureText(文本).width <br/>
</div>
</body>
</html>