-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtextBaseline.html
39 lines (38 loc) · 997 Bytes
/
textBaseline.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
<!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="alphabetic">alphabetic</option>
<option value="top">top</option>
<option value="hanging">hanging</option>
<option value="middle">middle</option>
<option value="ideographic">ideographic</option>
<option value="bottom">bottom</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('textBaseline', 0, 100);
function drawText(e) {
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.textBaseline = e.value;
ctx.fillText('textBaseline', 0, 100);
}
</script>
</body>
</html>