css文本省略;多行文本折叠

1、单行文本省略:

CSS代码:

.report_con{
    width: 6rem;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

HTML代码:

<div class="report_con">
    工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容
</div>

效果展示:

 

2、多行文本省略:

CSS代码:

.news_info{
    width: 6.24rem; 
    font-size: .28rem;
    color: #333333;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

HTML代码:

<div class="news_info">
    关于做好我省工程建设项目的通知做好我省工程省工程建设项目的通知做好我省工程 关于做好我省工程建设项目的通知做好我省工程省工程建设项目的通知做好我省工程 关于做好我省工程建设项目的通知做好我省工程省工程建设项目的通知做好我省工程 关于做好我省工程建设项目的通知做好我省工程省工程建设项目的通知做好我省工程 
</div>

效果展示:

3:多行文本折叠:

CSS代码:

.report_con {
    font-size: .28rem;
    color: rgb(102, 102, 102);
    margin-top: .2rem;

    overflow: hidden;
}

.show {
    line-height: .6rem;
    font-size: .26rem;
    color: rgba(102, 102, 102, .4);
    text-align: center;
    box-shadow: 0 .05rem .05rem -1px rgba(255, 255, 255, .8);
    display: flex;
    justify-content: space-around;
    background-image: linear-gradient(rgba(255, 255, 255, .8), rgba(255, 255, 255, .9));
    display: none;
}

HTML代码:

<div class="report_con">
    工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容工作报告内容
</div>
<div class="show">展开</div>

JQ代码:

var contNum = $(".report_con");
var slideHeight = 82; //px
for (var i = 0; i < contNum.length; i++) {
    let defHeight = $(contNum[i]).height();
	if (defHeight >= slideHeight) {
		$($('.show')[i]).show();
		fold($(contNum[i]), defHeight, i);
	}
}

function fold(obj, defHeight, index) {
    obj.css('height', slideHeight + 'px');
    $($('.show')[index]).click(function() {
	    var curHeight = obj.height();
	    if (curHeight == slideHeight) {
		    obj.animate({
		    	height: defHeight
		    }, "normal");
		    $($('.show')[index]).html('隐藏');
	    } else {
		    obj.animate({
		    	height: slideHeight
		    }, "normal");
		    $($('.show')[index]).html('展开');
	    }
	    return false;
    });
}

 效果展示:

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值