-webkit-line-clamp

 

-o-ellipsis-lastline

 

jQuery

除了各个浏览器私有的属性,有没有跨浏览器的解决方法呢?当然是通过js实现啦!(通过从后向前逐个删除末尾字符,直至元素的高度小于父元素高度)

$(".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)(\.\.\.)?$/, "..."));
    };
});

相关文章:

  • 2022-01-16
  • 2022-01-07
  • 2022-12-23
  • 2022-12-23
  • 2022-03-08
  • 2022-12-23
猜你喜欢
  • 2022-03-01
  • 2021-11-20
  • 2021-09-16
  • 2022-12-23
相关资源
相似解决方案