DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> HTML基礎知識 >> HTML和Xhtml >> HTML5 Canvas的文本筆觸顏色
HTML5 Canvas的文本筆觸顏色
編輯:HTML和Xhtml     

要設置筆觸顏色HTML5 Canvas的文本,我們可以使用的strokeStyle畫布的背景和strokeText()方法。

  1. context.strokeStyle=[value];
  2. context.strokeText("Hello World!", x, y);


先看下個例子:

<!DOCTYPE HTML>
<html>
<head>
<title>html5_canvas_text_stroke</title>
<style>
body {margin: 0px;padding: 0px;}
#myCanvas {border: 1px solid #9C9898; margin:0 auto;margin-top:200px; margin-left:100px;}
</style>
<script>
   window.onload = function(){
    var canvas = document.getElementById("myCanvas");
    var context = canvas.getContext("2d");
 
    var x = 80;
    var y = 110;
    context.font = "60pt Calibri";
 
    context.lineWidth = 3;
    context.strokeStyle = "blue"; // stroke color
    context.strokeText("Hello World!", x, y);
};
</script>
</head>
<body>
 <canvas id="myCanvas" width="578" height="200">
 </canvas>
</body>
</html>

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved