function measureText(text, elem) {
if (!this.context) {
let measureStyle = getComputedStyle(elem, null);
this.context = document.createElement('canvas').getContext('2d');
this.context.font = measureStyle.getPropertyValue('font');
}
return this.context.measureText(text).width;
}
网友评论