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);
}

你可能感兴趣的:(javascript,前端,html)