6-2文字加粗
来源:6-2 编程练习
田马达加斯加
2018-10-29 15:11:10
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>canvas字体</title>
<style>
canvas{background-color:lightblue;}
</style>
</head>
<body>
<canvas id="canvas" width="800px" height="800px">您的浏览器不支持canvas
</canvas>
<script>
var canvas=document.getElementById("canvas");
var context=canvas.getContext('2d');
//此处补充代码
var str1="你好!";
context.font="30px '微软雅黑'";
// context.lineWidth=8;
context.fillStyle="blue";
context.textAlign="center";
//context.textBaseLine="bottom";
context.fillText(str1,400,400);
var width=context.measureText(str1).width;
var str2="文字的宽度是:"+width;
context.fillText(str2,400,500);
</script>
</body>
</html>
文字加粗怎么设置啊
1回答
在font属性前面添加样式:
文字的位置是正确的。
自己添加测试下,祝学习愉快!
相似问题