HTML5文本样例
1、样例背景
利用HTML5自带的属性,设置字体样式
2、实现源码
(1)HTML5
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style>
body{
99%;
height: 99%;
}
#canvas{
1000px;
height: 400px;
margin: 10px;
padding: 10px;
background: #FFF;
border: 1px dashed burlywood;
}
</style>
</head>
<body>
<canvas id="canvas" width="1000" height="400"></canvas>
<script type="text/javascript" src="js/hello.js" ></script>
</body>
</html>
(2)JavaScript
var canvas = document.getElementById('canvas');
context = canvas.getContext('2d');
context.font = '30px 微软雅黑';
context.fillStyle = 'lightcoral';
context.strokeStyle = 'cadetblue';
context.fillText('你好,桃树!',canvas.width/2-200,canvas.height/2+200);
context.strokeText('你好,桃树!',canvas.width/2-200,canvas.height/2+200);