Last active
August 29, 2015 14:11
-
-
Save wileam/20b36e50ec09fbcf29db to your computer and use it in GitHub Desktop.
多行溢出省略
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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