【发布时间】:2013-08-07 00:31:25
【问题描述】:
有没有办法只更改画布上下文的字体大小而无需知道/编写字体系列。
var ctx = document.getElementById("canvas").getContext("2d");
ctx.font = '20px Arial'; //Need to speficy both size and family...
注意:
ctx.fontSize = '12px'; //doesn't exist so won't work...
ctx.style.fontSize = '20 px' //doesn't exist so won't work...
//we are changing the ctx, not the canvas itself
其他说明:我可以执行以下操作:检测“px”在哪里,删除“px”之前的内容并将其替换为我的字体大小。但如果可能的话,我想要比这更简单的东西。
【问题讨论】:
标签: javascript canvas