怎么获的字体的宽高
function textSize(fontSize,fontFamily,text){ let span = document.createElement("span"); let result = {}; result.width = span.offsetWidth; result.height = span.offsetHeight; span.style.visibility = "hidden"; span.style.position = "absolute"; span.style.top="-200px"; span.style.fontSize = fontSize; span.style.fontFamily = fontFamily; span.style.display = "inline-block"; document.body.appendChild(span); if(typeof span.textContent != "undefined"){ span.textContent = text; }else{ span.innerText = text; } result.width = parseFloat(window.getComputedStyle(span).width) - result.width; result.height = parseFloat(window.getComputedStyle(span).height) - result.height; span.parentNode.removeChild(span); return result; }
“我相当乐意花一天的时间通过编程把一个任务实现自动化,除非这个任务手动只需要10秒钟就能完成”