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第二元素QQ20230616133309.png(7.5 KB, 下載次數: 33)
2023-6-16 13:34 上傳
聲明:本文內容由互聯網用戶自發貢獻,該文觀點僅代表作者本人。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。如發現本站有涉嫌抄襲侵權/違法違規的內容, 請發送郵件至201542412@QQ.com舉報,一經查實,本站將立刻刪除。
相關推薦
-
css在中去除button按鈕默認自帶的樣式的方法
這段代碼將清除按鈕的大部分默認樣式,讓它看起來更像一個普通的HTML元素,而不是一個瀏覽器風格化的按鈕。您可以根據需要進一步定製這些樣式。
-
用css清除html中li標籤列表自帶的點的方法
標籤自帶的點,您可以使用CSS的list-styl-ty屬性。這個屬性允許您控制列表項的標記樣式,包括去除標記。以下是具體操作方法
-
htm加css和js實現手機端隱藏查看剩餘點擊展開,剩餘%未閱讀
htm加css和js實現手機端隱藏查看剩餘點擊展開,剩餘%未閱讀js部分代碼:html部分css部分:其中.rticl-body是第一內容元素,.contnt第二元素...
-
CSS圓角樣式屬性寫法
CSS 圓角可以使用 border-radius 屬性來實現。這個屬性可以設置元素的四個角(上、右、下、左)的圓角半徑,從而使元素看起來像是有圓角的矩形。
-
原生javascript加css和html做一鍵複製功能。
原生jvscrit加css和html做一鍵複製功能。效果如下截圖:jvscrit代碼部分:css代碼:HTML代碼