|
htm加css和js实现手机端隐藏查看剩余点击展开,剩余%未阅读
js部分代码:
- if ($('.article-body').length) {
- if ($(".content").length) {
- var Content = $(".content");
- var Tipstext = $(".more-content-text");
- var OpenHeight = 1200;
- Content.css('maxHeight', '');
- var Totheight = Content.height();
- var size = Math.floor(Totheight / OpenHeight) - 1;
- if (size >= 2) {
- var curr = 1;
- var percent = Math.floor(100 - (100 / size) * curr);
- Content.css('maxHeight', OpenHeight + 'px');
- Tipstext.html('点击展开,剩余' + percent + '%未阅读');
- Tipstext.on("click", function() {
- getOpenMore(curr, size);
- });
- $(".pagelist").hide();
- } else {
- if (Totheight > 1500) {
- Content.css('maxHeight', OpenHeight + 'px');
- Tipstext.html('未完...展开全文');
- Tipstext.on("click", function() {
- getOpenMore(1, 1);
- });
- $(".pagelist").hide();
- } else {
- Content.css('maxHeight', '');
- $(".more-content").hide();
- $(".pagelist").show();
- }
- }
- function getOpenMore(curr_in, size) {
- if (curr_in < size - 1) {
- var curr = curr_in + 1;
- var percent = Math.floor(100 - (100 / size) * curr);
- Content.css('maxHeight', OpenHeight * curr + 'px');
- Tipstext.html('点击展开,剩余' + percent + '%未阅读');
- Tipstext.on("click", function() {
- getOpenMore(curr, size);
- });
- $(".pagelist").hide();
- } else {
- Content.css('maxHeight', '');
- $(".more-content").hide();
- $(".pagelist").show();
- }
- }
- }
- }
复制代码 html部分
- <div class="more-content">
- <div class="more-content-mask">
- </div>
- <div class="more-content-text">
- </div>
- </div>
复制代码 css部分:- .more-content .more-content-text {
- font-size: 14px;
- line-height: 40px;
- margin: 0 auto;
- color: #fff;
- background: #6f98b0;
- text-align: center;
- height: 40px;
- cursor: pointer;
- width: 90%;
- display: block;
- border-radius: 50px;
- }
复制代码 其中.article-body是第一内容元素,.content第二元素
|
上一篇:原生javascript加css和html做一键复制功能。下一篇:html中伪元素添加一些符号比如斜杠之类的,然后然后去掉结尾最后一个的方法
|