Javascript: Is it possible to set different font sizes for different texts in a 2D canvas?

有些话、适合烂在心里 提交于 2019-12-25 06:59:26

问题


Afaik, you can only set the font for the WHOLE canvas.

var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");  
ctx.font = "30px Arial"

I would like lets say, text1 to be "30px Arial" and text2 to be "10px Arial". Is this possible?


回答1:


Yes, its is possible:

//first text
ctx.font = "30px Arial";
ctx.fillText("Hello World",10,50);
//second text
ctx.font = "20px Arial";
ctx.fillText("Bell World",50,100);


来源:https://stackoverflow.com/questions/36801391/javascript-is-it-possible-to-set-different-font-sizes-for-different-texts-in-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!