文章内容页点击“展开阅读全文”的实现代码

文章内容页点击“展开阅读全文”的实现代码

1.CSS代码

.article_content {
	margin-bottom: 30px;
	color: #454545;
	padding: 20px 30px 0 30px;
	line-height: 40px;
}

.readall_box {
	position: relative;
	z-index: 9999;
	padding: 0 0 25px;
	margin-top: -200px;
	text-align: center;
}

.readall_box .read_more_mask {
	height: 200px;
	background: -moz-linear-gradient(bottom,rgba(255,255,255,0.1),rgba(255,255,255,0));
	background: -webkit-gradient(linear,0 top,0 bottom,from(rgba(255,255,255,0)),to(#fff));
	background: -o-linear-gradient(bottom,rgba(255,255,255,0.1),rgba(255,255,255,0))
}

.read_more_btn {
	cursor: pointer;
	font-size: 16px;
	color: #de686d;
	background: #fff;
	border-radius: 4px;
	border: 1px solid #de686d;
	line-height: 30px;
	padding: 5px 10px;
}

2. html代码

<div class="container">
            <h2>Jquery阅读全文</h2>
            <div class="article_content">
                <div>内容区域内容区域内容区域内容区域内容区域内容区域内容区域内容区域内容区域内容区域内容区域内容区域内容区域内容区域内容区域内容区域内容区域内容区域内容区域内容区域内容区域内容区域内容区域内容区域内容区域内容区域内容区域内容区域内容区域内容区域内容区域内容区域内容区域内容区域内容</div>
            </div>
            <div class="readall_box">
                <div class="read_more_mask"></div>
                <a class="read_more_btn" target="_self">阅读全文</a>
            </div>
        </div>

3. js代码

 //内容展示高度
 var widHeight = 300;
$(function(){
	showHideContent(false);
    //阅读全文
	$(document).on("click", ".read_more_btn", function () {
	    $('#article_content').height("").css({ 'overflow': 'hidden' });
	    $('.readall_box').hide()
	});
})
 //阅读全文使用
function showHideContent(isBo) {
    if (isBo) {
        //这里是不做高度判断,直接全展示
         $('.readall_box').hide();
    } else {
        var contentId$ = $("#article_content");
        var artHeight = contentId$.height();
        if (artHeight > widHeight) {
            contentId$.height(widHeight - 100).css({ 'overflow': 'hidden' });
        } else {
            $('.readall_box"]').hide();
        }
    }
}

实现效果如下
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值