在非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!
转载请注明原文地址: https://lol.8miu.com/read-22573.html