HLJ 发布于
2018-08-20 11:08:23

HTML5 Canvas设置文本颜色

要使用HTML5 Canvas设置文本颜色,我们可以将画布上下文的fillStyle属性设置为颜色字符串,十六进制值或RGB值。

<!DOCTYPE HTML>
<html>
<head>
<style>
    body { margin: 0px;padding: 0px;}
</style>
</head>

<body>
<canvas id="myCanvas" width="578" height="200"></canvas>
<script>
    var canvas = document.getElementById('myCanvas');
    var context = canvas.getContext('2d');

    context.font = '40pt Calibri';
    context.fillStyle = 'blue';
    context.fillText('Hello World!', 150, 100);
</script>
</body>
</html>
当前文章内容为原创转载请注明出处:http://www.good1230.com/detail/2018-08-20/153.html
最后生成于 2023-06-18 18:37:54
此内容有帮助 ?
0