echarts在rem布局适配中字体如何适配

echarts在rem布局适配中字体如何适配

rem布局固然重要;但是echarts也需要在随着rem动态改变数值:

直接上代码

接上代码

1
2
3
4
5
6
7
8
9
10
11

// 字体适配
FontChart(res) {
        //获取到屏幕的宽度
        var clientWidth =
          window.innerWidth ||
          document.documentElement.clientWidth ||
          document.body.clientWidth;
        if (!clientWidth) return; //报错拦截:
        let fontSize = 10 * (clientWidth / 1920);
        return res * fontSize;
      },

解释一下含义:该方法为在1920尺寸中;以1rem = 10px换算关系的设计稿
使用时直接调用:若10px则为: width: this.ChartFont(0.1)

假如:设计稿尺寸不是1920了;则修改1920位置处;
则:let fontSize = 10 * (clientWidth /尺寸)

若换算关系不为1rem =

猜你喜欢

转载自blog.csdn.net/weixin_50885665/article/details/130408700