js点击阅读全文

46 篇文章 0 订阅
41 篇文章 1 订阅

html

<div class="wrap">
	<div class="detail_main content_wrap">
		{$info['content']|htmlspecialchars_decode}
	</div>
	<div class="unfold-field">
		<!-- <div class="unflod-field_mask"></div> -->
		<div class="unfold-field_text">
			<!-- <span>展开全文</span> -->
			<div class="read_article">点击阅读全文</div>
		</div>
	</div>
</div>

css

/* 阅读全文 */
.wrap {
	max-height: 7.9rem;
	/*设置默认高度*/
	overflow: hidden;
	margin-bottom: 1rem;
	position: relative;
	visibility: hidden;
}
/*展开全文*/

.unfold-field {
	/* display: none; */
	position: absolute;
	font-size: 0;
	bottom: 0;
	width: 100%;
	height: 0;
	z-index: 3;
}

.unfold-field .unflod-field_mask {
	height: 0.78rem;
	width: 100%;
	background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, hsla(0, 0%, 100%, 0)), to(#fff));
	background-image: linear-gradient(-180deg, hsla(0, 0%, 100%, 0), #fff);
}
.read_article{
	width: 6.9rem;
	height: 0.88rem;
	line-height: 0.88rem;
	color: #fff;
	background: #000000;
	text-align: center;
	font-size: 0.36rem;
	border-radius:0.44rem;
	margin: 0.5rem auto;
	margin-top: -0.87rem;
	-moz-box-shadow:0px -10px 10px #fff; 
	-webkit-box-shadow:0px -10px 10px #fff; 
	box-shadow:0px -5px 15px #fff;
}
.unfold-field_text{
	background: #fff;
}

js

//阅读全文
var unfoldField = document.querySelector(".read_article");
var wrapH = document.querySelector(".wrap").offsetHeight;
var wrap = document.querySelector(".wrap");
var contentH = document.querySelector(".content_wrap").offsetHeight;
//如果实际高度大于设置的默认高度就把超出的部分隐藏
if(contentH > wrapH) {
	unfoldField.style.display = "block";
}
wrap.style.visibility = "visible";

unfoldField.onclick = function() {
	this.parentNode.removeChild(this);
	wrap.style.maxHeight = "100%";
	wrap.style.visible = "visible";
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值