给文章加入阅读全文按钮阅读剩下内容

给文章加入阅读全文按钮阅读剩下内容 第2张插图

这个功能本身十分鸡肋,但是为了页面美观还是有必要的
首先是html按钮

<div class="readall_box" >
  <div class="read_more_mask"></div>
  <a class="read_more_btn" target="_self">阅读全文</a>
</div>

下面是JavaScript算法代码

<script type="text/javascript">
  $(function(){
    var widHeight = $(window).height();
    var artHeight = $('.art-content').height();
    if(artHeight>(widHeight*1.5)){
      $('.art-content').height(widHeight*1.5-285).css({'overflow':'hidden'});
      var article_show = true;
      $('.read_more_btn').on('click',bindRead_more);
    }else{
      article_show = true;
      $('.readall_box').hide().addClass('readall_box_nobg');
    }
    function bindRead_more(){
      if(!article_show){
        $('.art-content').height(widHeight*1.5).css({'overflow':'hidden'});
        $('.readall_box').show().removeClass('readall_box_nobg');
        article_show = true;
      }else{
        $('.art-content').height("").css({'overflow':'hidden'});
        $('.readall_box').show().addClass('readall_box_nobg');
        $('.readall_box').hide().addClass('readall_box_nobg');
        article_show = false;
      }
    }
  })
</script>

需要把所有的.art-content替换成你自己的文章div的class或者id标签
下面是css样式代码

<style type="text/css">
* {padding: 0; margin: 0; font-family: 'Microsoft Yahei';}
.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;}
.read_more_btn:hover{background:#de686d;color:#fff;}
</style>

大功告成效果图
给文章加入阅读全文按钮阅读剩下内容 第3张插图

免责声明

本站提供的一切软件、教程和内容信息仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络收集整理,如果您喜欢该程序和内容,请支持正版,购买注册,得到更好的正版服务。我们非常重视版权问题,如有侵权请邮件与我们联系处理。敬请谅解!
如若转载,请注明出处:https://www.zxki.cn/3764.html

上一篇 2022-5-16 12:38
下一篇 2022-5-16 16:39

相关推荐

发表评论

为了防止灌水评论,登录后即可评论!

已有 1 条评论