js 获取文本行数

<div id="content">
	若干文字内容
</div>
getLineCount () {
    
    
	// 获取实际文本行高
	const style = window.getComputedStyle(document.getElementById('content'), null);
	const fontSize = style.fontSize;
	const paddingTop = style.paddingTop.replace('px', '');
	const paddingBottom = style.paddingBottom.replace('px', '');
	const lineHeight = (style.lineHeight === 'normal' ? fontSize : style.lineHeight).replace('px', '');
	const height = style.height.replace('px', '');
	debugger;
	if (height / lineHeight > this.lineLimit) {
    
    
		this.isNeedShowMore = true;
	} else {
    
    
		this.isNeedShowMore = false;
	}
	console.log(height / lineHeight);
}

猜你喜欢

转载自blog.csdn.net/fth1002853070/article/details/129618550