通过点击“更多”来展开
more() {
var items = document.getElementById("items"); //获取内部span对象
var itemsHeight = items.scrollHeight; //文本的实际高度
if (!this.isMore) {
if (itemsHeight <= 126) {//当文本实际高度小于特定高度(三行)
$("#coll-centent").css("height", itemsHeight);//将文本实际高度赋给外部div
} else {//当文本实际高度大于特定高度(三行)
$("#items").css("overflow", "scroll");//将内部span设置为滚动
$("#coll-centent").css("height", 126);
}
} else {
if ($("#coll-centent").height() > 40) {
$("#items").css("overflow", "hidden");
$("#coll-centent").css("height", 40);
}
}
this.isMore = !this.isMore;//是否展开的标记
},
关键:
1.获取文本的实际高度
2.比较文本实际高度和外部div高度