HTML5 Canvas的文本顏色,我們可以使用的字體在畫布范圍內的屬性。
下面我們就做一個簡單的實例為大家講解下,基本語法:
- context.fillStyle=[value];
HTML5 Canvas Text Color 實例
<!DOCTYPE HTML>
<html>
<head>
<title>html5_canvas_text_color</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 = 150;
var y = 100;
context.font = "40pt Calibri";
context.fillStyle = "#0000ff"; // text color
context.fillText("Hello webjx!", x, y);
};
</script>
</head>
<body>
<canvas id="myCanvas" width="578" height="200">
</canvas>
</body>
</html>