How to get Text object font-size after modifying object

后端 未结 4 2051
旧时难觅i
旧时难觅i 2021-01-18 06:10

How can I get Text object font size after modifying object in fabric.js?

Below is my code.

var text = new fabric.Text(imgText, {
            


        
4条回答
  •  情歌与酒
    2021-01-18 06:55

    This is the vanilla js solution.

    I am not able to get FontSize.

    You can achieve fontSize using the computedStyle like

      let style = window.getComputedStyle(text, null).getPropertyValue('font-size');
      let fontSize = parseFloat(style); 
    

    https://developer.mozilla.org/de/docs/Web/API/Window/getComputedStyle

    In addition to this I recommend you to work with vw and vh

    .text {
      font-size: 10vw;
    }
    

    https://web-design-weekly.com/2014/11/18/viewport-units-vw-vh-vmin-vmax/

    All together gives us https://jsfiddle.net/a8woL1eh/

提交回复
热议问题