Skip to content

Latest commit

 

History

History
34 lines (30 loc) · 697 Bytes

文本溢出.md

File metadata and controls

34 lines (30 loc) · 697 Bytes
单行文本溢出
.text-ellipsis {
    text-overflow:ellipsis;
    white-space:nowrap; 
    overflow:hidden; 
}
多行文本溢出
.multiple-text-ellipsis {
    display: -webkit-box;
    overflow : hidden;
    text-overflow: ellipsis;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}
jQuery实现文本溢出
function ellipsis(element, contentBox) {
    $(element).each(function(i){
        var divH = $(this).height();
        var $content = $(contentBox, $(this)).eq(0);
        while ($content.outerHeight() > divH) {
            $content.text($content.text().replace(/(\s)*([a-zA-Z0-9]+|\W)(\.\.\.)?$/, "..."));
        };
    });
}