代码
提交代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>慕课网Wiki</title>
<style>
#imooc{
border:1px solid #ccc;
}
</style>
</head>
<body>
<canvas id="imooc">您的浏览器不支持 HTML5 canvas 标签</canvas>
<script>
const canvas = document.getElementById('imooc');
canvas.width=300;
canvas.height=300;
const ctx = canvas.getContext('2d');
ctx.fillStyle = "#456795"
ctx.font="16px 微软雅黑"
ctx.textAlign = "left"
ctx.fillText("慕课Wiki left", 150, 30)
ctx.textAlign = "center"
ctx.fillText("慕课Wiki center", 150, 60)
ctx.textAlign = "right"
ctx.fillText("慕课Wiki right", 150, 90)
ctx.textAlign = "start"
ctx.fillText("慕课Wiki start", 150, 120)
ctx.textAlign = "end"
ctx.fillText("慕课Wiki end", 150, 150)
ctx.direction = "rtl"; //设定画布的渲染方向
ctx.fillStyle = "red"
ctx.font="16px 微软雅黑"
ctx.textAlign = "left"
ctx.fillText("慕课Wiki left", 150, 180)
ctx.textAlign = "center"
ctx.fillText("慕课Wiki center", 150, 210)
ctx.textAlign = "right"
ctx.fillText("慕课Wiki right", 150, 240)
ctx.textAlign = "start"
ctx.fillText("慕课Wiki start", 150, 270)
ctx.textAlign = "end"
ctx.fillText("慕课Wiki end", 150, 300)
//绘制中间参考线
ctx.beginPath()
ctx.strokeStyle="#ccc";
ctx.moveTo(150,0);
ctx.lineTo(150,300);
ctx.stroke();
//绘制中间参考线
ctx.beginPath()
ctx.strokeStyle="#ccc";
ctx.moveTo(0,150);
ctx.lineTo(300,150);
ctx.stroke();
</script>
<body>
</html>
运行结果