标签:
多行文本溢出显示省略号(...)的方法
现在的浏览器都支持text-overflow:ellipsis属性,用来实现单行文本的溢出显示省略号。
如:
单行文本:
overflow:hidden;white-space:nowrap;text-overflow:ellipsis
一些其他技巧可参考:http://www.zhangxinxu.com/wordpress/?p=230
多行文本:
text-overflow:ellipsis;
display:-webkit-box;
-webkit-line-clamp:3;
-webkit-box-orient:vertical;
但是这个属性并不支持多行文本。那么有没有方法在多行文本上实现同样的效果呢?
$(".content").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)(\.\.\.)?$/, "..."));
};
});
标签:
原文地址:http://www.cnblogs.com/mrxia/p/4267329.html