Created
April 17, 2014 05:51
-
-
Save plutochill/10956060 to your computer and use it in GitHub Desktop.
多行文本溢出显示省略号(...)的方法
This file contains hidden or 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)(\.\.\.)?$/, "...")); | |
}; | |
}); | |
//css | |
p { | |
overflow : hidden; | |
text-overflow: ellipsis; | |
display: -webkit-box; | |
-webkit-line-clamp: 2; | |
-webkit-box-orient: vertical; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment