Echarts实战案例代码(45):拼接屏字体自适应的解决方案

it2025-01-27  16

在非1920*1080,16:9模式下,字体设置成固定值,在实际显示的时候会有误差。此时,需要将字体设置成自适应。

封装函数

function fontSize(res) { let docEl = document.documentElement, clientWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; if (!clientWidth) return; let fontSize = 100 * (clientWidth / 1920); return res * fontSize; } window.addEventListener("resize", function () { console.log(fontSize(0.12)); })

Echarts调用

textStyle:{ fontSize: fontSize(0.12), }

Done!

最新回复(0)