const diffTextCountFontSize = (strText, boxWidth) => {
let textLength = strText.length;
let l = 0;
for (const i in strText) {
if (strText.charCodeAt(i) > 255) {
l += 1;
}
}
const numLength = textLength - l;
if (l > 0) {
if (numLength % 2 === 0) {
textLength = parseInt((strText.length - l) / 2, 10) + l;
} else {
textLength = parseInt((strText.length - l) / 2, 10) + 1 + l;
}
} else {
textLength *= 0.65;
}

return (boxWidth / textLength) * 1.25;
};

 

strText //字符串内容

boxWidth //div固定宽度

(需根据情况,对数据进行相应调整)

 posted on 2017-10-11 18:41  weimo10235  阅读(413)  评论(0)    收藏  举报