在html5的画布上,怎么使文字变大并加粗显示?
1个回答
展开全部
canvas有一个font属性,用font属性先设定好文字的字体,加粗,倾斜,字号,然后用fillText 或者strokeText插入文字就好了,
给个例子:
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">
window.onload=function () {
var content = document.getElementById("canvas");
var cxt = content.getContext("2d");
cxt.font = "bold 30px Arial";
//fillText方式
cxt.fillText("随便写点儿啥", 50, 50);
}
</script>
</head>
<body>
<canvas id="canvas" width="300" height="300"></canvas>
</body>
</html>
给个例子:
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">
window.onload=function () {
var content = document.getElementById("canvas");
var cxt = content.getContext("2d");
cxt.font = "bold 30px Arial";
//fillText方式
cxt.fillText("随便写点儿啥", 50, 50);
}
</script>
</head>
<body>
<canvas id="canvas" width="300" height="300"></canvas>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询