-
Notifications
You must be signed in to change notification settings - Fork 0
/
textAlign.html
38 lines (37 loc) · 920 Bytes
/
textAlign.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>fillRect</title>
<style>
canvas {
border: 1px solid #d9d9d9;
}
</style>
</head>
<body>
<select id="type" onchange="drawText(this)">
<option value="start">start</option>
<option value="center">center</option>
<option value="end">end</option>
<option value="left">left</option>
<option value="right">right</option>
</select>
<canvas id="canvas" width="400" height="300">
不支持canvas
</canvas>
<script>
var canvas = document.getElementById('canvas');
var ctx = '';
ctx = canvas.getContext('2d');
ctx.font = '20px Arial';
ctx.fillStyle = 'red';
ctx.fillText('textAlign', 0, 100);
function drawText(e) {
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.textAlign = e.value;
ctx.fillText('textAlign', 0, 100);
}
</script>
</body>
</html>