产品效果
少于5行文字,则全部显示,多于5行文字,则显示 “查看全文”; 点击展开不用收起
方案思路
利用 父级盒子的高度和
overflow: hidden;
和position: absolute;
代码具体实现
HTML
<!-- isShowIntro: 是否展开查看全文 -->
<view
class="item-content text-f15"
:class="isShowIntro?'content-text line5':' content-text-show'">
{{content || ''}}
<span
class="primary"
v-if="isShowIntro"
@click.stop="()=>{ this.isShowIntro=false }">
查看全文
</span>
</view>
style
.item-content {
text {
line-height: 46rpx;
}
.content {
margin-bottom: 8rpx;
}
.primary {
font-size: 28rpx;
color: #1EA0F1;
}
// 查看全文 - 收起
&.content-text {
position: relative;
max-height: 228rpx;
line-height: 46rpx;
overflow: hidden;
text-align: left;
.primary {
position: absolute;
top: 186rpx;
left: 0;
width: 100%;
height: 60rpx;
background-color: #fff;
}
}
// 查看全文 - 展开
&.content-text-show {
position: relative;
line-height: 46rpx;
.primary {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
background-color: #fff;
display: none;
opacity: 0;
}
}
}