console
window.onload = function(){
var text = document.getElementById("overflowhidden");
var str = text.innerHTML;
window.onresize = function(){
overflowhidden("overflowhidden",3,str);
}
overflowhidden("overflowhidden",3,str);
}
var overflowhidden = function(id, rows, str){
var text = document.getElementById(id);
var style = getCSS(text);
var lineHeight = style["line-height"];
var at = rows*parseInt(lineHeight);
var tempstr = str;
text.innerHTML = tempstr;
var len = tempstr.length;
var i = 0;
if(text.offsetHeight <= at){
}
else {
var temp = "";
text.innerHTML = temp;
while(text.offsetHeight <= at){
temp = tempstr.substring(0, i+1);
i++;
text.innerHTML = temp;
}
var slen = temp.length;
tempstr = temp.substring(0, slen-1);
len = tempstr.length
text.innerHTML = tempstr.substring(0, len-3) +"...";
text.height = at +"px";
}
}
<body>
<div class="common">
<h2>example</h2>
<div class = "demo">
<div class="text" id="overflowhidden">吉日兮辰良,穆将愉兮上皇;抚长剑兮玉珥[ěr],璆[qiú]锵鸣兮琳琅;瑶席兮玉瑱[zhèn],盍[hé]将把兮琼英;灵连蜷兮既留,烂昭昭 游兮周章;灵皇皇兮既降,猋[biāo]远举兮云中;览冀洲兮有余,横四海兮焉穷;思夫君[zhèn][zhèn][zhèn]兮太[zhèn]息,极劳心兮忡忡。</div>
</div>
</div>
<script type="text/javascript" src="js/common.js"></script>
</body>
.text{display: -webkit-box;
display: -moz-box;
white-space: pre-wrap;
word-wrap: break-word;
overflow: hidden;
text-overflow: ellipsis;
-webkit-box-orient: vertical;
-webkit-line-clamp:2;
}