標籤:canvas繪製字型-屬性設定2
650) this.width=650;" src="http://s1.51cto.com/wyfs02/M00/8C/F4/wKiom1h_Kluw5pTUAABqwT-gVms033.png-wh_500x0-wm_3-wmp_4-s_1026399509.png" title="QQ20170118164139.png" alt="wKiom1h_Kluw5pTUAABqwT-gVms033.png-wh_50" />
html結構
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>canvas27</title>
<link rel="stylesheet" href="">
</head>
<body>
<canvas id="canvas" style ="border:1px solid #aaa;diplay:block;margin:50px auto;">
當前瀏覽器不支援canvas,請更換瀏覽器後再試
</canvas>
</body>
</html>
js指令碼
<script>
window.onload = function(){
var canvas = document.getElementById("canvas");
canvas.width = 800;
canvas.height = 800;
context = canvas.getContext("2d");
context.fillStyle = "#058";
context.font = "lighter 40px impact";
context.fillText("歡迎學習",40,100);
context.font = "normal 40px impact";
context.fillText("歡迎學習",40,200);
context.font = "bold 40px impact";
context.fillText("歡迎學習",40,300);
context.font = "bolder 40px impact";
context.fillText("歡迎學習",40,400);
}
</script>
本文出自 “素顏” 部落格,請務必保留此出處http://suyanzhu.blog.51cto.com/8050189/1892949
canvas繪製字型-屬性設定2