Change font size of Canvas without knowing font family

前端 未结 5 1012
遥遥无期
遥遥无期 2020-12-30 00:06

Is there a way to only change the font size of a canvas context without having to know/write the font family.

 var ctx = document.getElementById(\"canvas\").         


        
5条回答
  •  一向
    一向 (楼主)
    2020-12-30 00:11

    A cleaner way to not worry about scraping every other parameter:

    canvas.style.font = canvas.getContext("2d").font;
    canvas.style.fontSize = newVal + "px";
    
    canvas.getContext("2d").font = canvas.style.font;
    

提交回复
热议问题