微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

HTML5文本样例

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.height/2+200);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。