Skip to content

Instantly share code, notes, and snippets.

@wileam
Last active August 29, 2015 14:11
Show Gist options
  • Save wileam/20b36e50ec09fbcf29db to your computer and use it in GitHub Desktop.
Save wileam/20b36e50ec09fbcf29db to your computer and use it in GitHub Desktop.
多行溢出省略
//webkit
p {
overflow : hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
}
//opera
p {
overflow:hidden;
white-space:normal;
height:3em;
text-overflow: –o-ellipsis-lastline;
}
//jquery
//从后向前逐个删除末尾字符,直至元素的高度小于父元素高度
$(".figcaption").each(function(i){
var divH = $(this).height();
var $p = $("p", $(this)).eq(0);
while ($p.outerHeight() > divH) {
$p.text($p.text().replace(/(\s)*([a-zA-Z0-9]+|\W)(\.\.\.)?$/, "..."));
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment