[ 登录注册 ]

yuyan

HTML5文本样例

2016-08-25 22:33:40 admin 返回上一页

HTML5文本样例


1、样例背景

     利用HTML5自带的属性,设置字体样式


2、实现源码

(1)HTML5

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
		<style>
		    body{
		    	width: 99%;
		    	height: 99%;
		    }
			#canvas{
				width: 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);



文章来源:http://www.bozhiyue.com/web/yuyan/2016/0825/433310.html
返回上一页    返回分类 上一篇:   下一篇:
相关