htm加css和js实现手机端隐藏查看剩余点击展开,剩余%未阅读

htm加css和js实现手机端隐藏查看剩余点击展开,剩余%未阅读
js部分代码:
  1. if ($('.article-body').length) {
  2.   if ($(".content").length) {
  3.     var Content = $(".content");
  4.     var Tipstext = $(".more-content-text");
  5.     var OpenHeight = 1200;
  6.     Content.css('maxHeight', '');

  7.     var Totheight = Content.height();
  8.     var size = Math.floor(Totheight / OpenHeight) - 1;

  9.     if (size >= 2) {
  10.       var curr = 1;
  11.       var percent = Math.floor(100 - (100 / size) * curr);
  12.       Content.css('maxHeight', OpenHeight + 'px');
  13.       Tipstext.html('点击展开,剩余' + percent + '%未阅读');
  14.       Tipstext.on("click", function() {
  15.         getOpenMore(curr, size);
  16.       });
  17.       $(".pagelist").hide();
  18.     } else {
  19.       if (Totheight > 1500) {
  20.         Content.css('maxHeight', OpenHeight + 'px');
  21.         Tipstext.html('未完...展开全文');
  22.         Tipstext.on("click", function() {
  23.           getOpenMore(1, 1);
  24.         });
  25.         $(".pagelist").hide();
  26.       } else {
  27.         Content.css('maxHeight', '');
  28.         $(".more-content").hide();
  29.         $(".pagelist").show();
  30.       }
  31.     }

  32.     function getOpenMore(curr_in, size) {
  33.       if (curr_in < size - 1) {
  34.         var curr = curr_in + 1;
  35.         var percent = Math.floor(100 - (100 / size) * curr);
  36.         Content.css('maxHeight', OpenHeight * curr + 'px');
  37.         Tipstext.html('点击展开,剩余' + percent + '%未阅读');
  38.         Tipstext.on("click", function() {
  39.           getOpenMore(curr, size);
  40.         });
  41.         $(".pagelist").hide();
  42.       } else {
  43.         Content.css('maxHeight', '');
  44.         $(".more-content").hide();
  45.         $(".pagelist").show();
  46.       }
  47.     }
  48.   }
  49. }
复制代码
html部分
  1. <div class="more-content">
  2. <div class="more-content-mask">
  3.         </div>
  4.         <div class="more-content-text">
  5.         </div>
  6. </div>
复制代码
css部分:
  1. .more-content .more-content-text {
  2.     font-size: 14px;
  3.     line-height: 40px;
  4.     margin: 0 auto;
  5.     color: #fff;
  6.     background: #6f98b0;
  7.     text-align: center;
  8.     height: 40px;
  9.     cursor: pointer;
  10.     width: 90%;
  11.     display: block;
  12.     border-radius: 50px;
  13. }
复制代码
其中.article-body是第一内容元素,.content第二元素

htm加css和js实现手机端隐藏查看剩余点击展开,剩余%未阅读




上一篇:原生javascript加css和html做一键复制功能。
下一篇:html中伪元素添加一些符号比如斜杠之类的,然后然后去掉结尾最后一个的方法
如无回复请发邮件