Skip to content

Instantly share code, notes, and snippets.

View BryanYang's full-sized avatar

Bryan Yang BryanYang

View GitHub Profile
// 测量字符串长度
export function measureText(pText: string, pFontSize: number) {
let lDiv = document.createElement('div');
document.body.appendChild(lDiv);
lDiv.style.fontSize = '' + pFontSize + 'px';
lDiv.style.position = 'absolute';
lDiv.style.visibility = 'hidden';
lDiv.innerHTML = pText;