在我的应用程序中,我想检查是否存在文本溢出(省略号)。为此,我检查e.offsetWidth < e.scrollWidth
但它们返回相等的值,表示offsetWidth
返回错误的值。这是我的实现:
CSS :
.less{
display: block;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.complete{
word-wrap: break-word;
}
.collapse{
color:blue;
font-size:13px;
cursor:pointer;
}
.hideElement{
display: none;
}
#seemore:after{
content: " \000BB";
}
#seeless:before{
content:"\000AB\ ";
}
#description {
width: 100%;
overflow: hidden;
}
HTML :
<div id = "description">
<div id="lessdescription" class="less"></div>
<div id="seemore" class="collapse"></div>
<div id="seeless" class="collapse hideElement"></div>
</div>
JS
function manageReportDescription() {
var descriptionElement = document.getElementById("lessdescription");
return descriptionElement.offsetWidth < descriptionElement.scrollWidth;
}
我想使用纯JS属性(不依赖于jQuery)