HTML5 Canvas 文本【每日一段代码32】

<head>
<title>HTML5 Canvas 文本 </title>
<script type="text/javascript">
window.onload=function(){
var canvas=document.getElementById("myCanvas");
var context=canvas.getContext("2d");
context.font="40pt 微软雅黑";
context.fillStyle="#09f";
context.textAlign="center";
context.textBaseline="middle";
context.fillText("www.naokr.com",canvas.width/2,120);
}
</script>
</head>
<body style="margin:100px 10px;">
<canvas id="myCanvas" width="600" height="250" style="border:2px solid #06f;"></canvas>
</body>
</html>

 

显示效果如下:

 

实例来自网络。传送门:http://demo.cnmsdn.com/demo40.html

posted on 2012-03-01 22:20  Cosimo  阅读(250)  评论(0编辑  收藏  举报

导航