代碼
提交代碼
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>慕課網(wǎng)Wiki</title>
<style>
#imooc{
border:1px solid #ccc;
}
</style>
</head>
<body>
<canvas id="imooc">您的瀏覽器不支持 HTML5 canvas 標(biāo)簽</canvas>
<script>
const canvas = document.getElementById('imooc');
canvas.width=400;
canvas.height=240;
const ctx = canvas.getContext('2d');
ctx.fillStyle="#456795";
ctx.font="20px 微軟雅黑";
ctx.beginPath()
ctx.strokeStyle="#ccc";
ctx.moveTo(20,20);
ctx.lineTo(380,20);
ctx.stroke();
ctx.textBaseline="top" //設(shè)置基線在文本頂部,文本和基線重合
ctx.fillText("慕課Wiki textBaseline = top", 20,20)
ctx.beginPath()
ctx.strokeStyle="#ccc";
ctx.moveTo(20,60);
ctx.lineTo(380,60);
ctx.stroke();
ctx.textBaseline="hanging" //設(shè)置文本懸掛在基線上,文本和基線沒有重合
ctx.fillText("慕課Wiki textBaseline = hanging", 20,60)
ctx.beginPath()
ctx.strokeStyle="#ccc";
ctx.moveTo(20,100);
ctx.lineTo(380,100);
ctx.stroke();
ctx.textBaseline="middle" //設(shè)置基線在文本中間
ctx.fillText("慕課Wiki textBaseline = middle", 20,100)
ctx.beginPath()
ctx.strokeStyle="#ccc";
ctx.moveTo(20,140);
ctx.lineTo(380,140);
ctx.stroke();
ctx.textBaseline="alphabetic" //標(biāo)準(zhǔn)的字母基線
ctx.fillText("慕課Wiki textBaseline = alphabetic", 20,140)
ctx.beginPath()
ctx.strokeStyle="#ccc";
ctx.moveTo(20,180);
ctx.lineTo(380,180);
ctx.stroke();
ctx.textBaseline="ideographic"
ctx.fillText("慕課Wiki textBaseline = ideographic", 20,180)
ctx.beginPath()
ctx.strokeStyle="#ccc";
ctx.moveTo(20,220);
ctx.lineTo(380,220);
ctx.stroke();
ctx.textBaseline="bottom"
ctx.fillText("慕課Wiki textBaseline = bottom", 20,220)
</script>
<body>
</html>
運行結(jié)果