话不多说,进入正题,直接上代码,相关简介在注释里有,皆为细读HTML5著作经典所学,分享给大家!
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
* {
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<canvas id="canvas" width="800px" height="800px" style="border: 1px solid black;"></canvas>
<script>
var canvas = document.getElementById("canvas")
var context = canvas.getContext("2d")
context.lineWidth=40
context.fillStyle="red"
context.strokeStyle="yellow"
context.font="70px weiruanyahei"
context.textAlign="center"
context.textBaseline="bottom"
context.fillText("Hello world",350,400)
context.beginPath()
context.globalAlpha=0.5
context.fillStyle="red"
context.fillRect(350,400,20,20)
</script>
</body>
</html>