第26章 canvas绘制文字

html

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript" src="26.js"></script>
<style type="text/css">
body{ margin:0; padding:0;}
</style>
</head>

<body onLoad="draw('canvas')">
<canvas id="canvas" width='800' height="300"></canvas>
</body>
</html>

js

// JavaScript Document
function draw(id){
    var canvas = document.getElementById(id);
    var context = canvas.getContext('2d');
    context.fillStyle = 'green';
    context.fillRect(0,0,800,300);
    context.fillStyle = '#fff';
    context.strokeStyle = '#fff';
    context.font = "bold 40px '字体','字体','微软雅黑','宋体'";
    context.textBaseline = 'hanging';
    context.textAlign = 'start';
    context.strokeText('anvas绘制文字',210,40);
    context.fillText('《一站式共享网络》',160,110);
    context.fillText('阅谁问君诵,水落清香浮',130,180);
    
}

效果图:
第26章 canvas绘制文字
 

相关推荐