javascript

当前位置:首页 > 前端 > javascript

JS点击显示更多内容

<div class="page-one"> <div class="max1200 clearfix"> <div class="page-one-title">{{ app(&#39;section&#39;).id...
<div class="page-one">
      <div class="max1200 clearfix">
            <div class="page-one-title">{{ app('section').id(19613).title }}</div>
            <div class="page-one-pp text-content">
                {{ app('section').id(19613).content.content | raw }}
            </div>
            <div class="read-more"><a href="javascript:;" class="load-more-btn">阅读更多</a></div>
      </div>
</div>

<style>
        .text-content {
            overflow: hidden;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 3; /* 默认显示两行文本 */
            white-space: normal;
            text-overflow: ellipsis;
        }
       .page-one-pp{font-size:13px;color:#000;line-height:2.2}
        .read-more{position:relative;margin-top:.35rem}
        .read-more a{font-weight:700;position:relative;display:inline-block;font-size:13px;color:#000;line-height:28px}
        .read-more a::before{position:absolute;left:0;bottom:0;width:100%;height:1px;background:#000;content:"";transition:all .5s;-webkit-transition:all .5s;-moz-transition:all .5s;-o-transition:all .5s;-ms-transition:all .5s}
        .read-more a:hover{opacity:1}
        .read-more a:hover::before{width:100%}
</style>
    
<script>
    $(document).ready(function() {
        $(".load-more-btn").on("click", function() {
            var textContent = $(".text-content");
            var btn = $(this);

            // 显示全部文本
            textContent.css("-webkit-line-clamp", "unset"); 

            // 隐藏按钮(点击后不再显示)
            btn.hide();
        });
    });
</script>


上一篇:瀑布流布局

下一篇:已经是最后一篇

相关内容

文章评论

表情

共 0 条评论,查看全部
  • 这篇文章还没有收到评论,赶紧来抢沙发吧~