功能介绍:文章内容太长,进入页面只显示部分内容,并且提示“展开剩余 76% ↓”,点击按钮显示全部内容!
js代码如下:
document.addEventListener("DOMContentLoaded", function() { const fullContent = document.getElementById('content').innerHTML if(fullContent.length > 800){ const partialContent = fullContent.substring(0, 600); const percent = (100 - (600 / fullContent.length) * 100).toFixed(0) document.getElementById('content').innerHTML = `${partialContent}<div class="read-box"><div class="read_mask"></div><div class="read_mod"><span class="read-button" id="showFullContent">展开剩余 ` + percent + `% ↓</span></div></div>`; document.getElementById('showFullContent').addEventListener('click', function() { document.getElementById('content').innerHTML = `${fullContent}`; this.style.display = 'none'; }); } });
css代码如下:
.read-box {
position: relative;
z-index: 9;
margin-top: -220px;
padding: 0 0 35px;
width: 101%;
text-align: center;
}
.read_mask {
height: 200px;
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,.1),rgba(255,255,255,0));
}
.read-box .read_mod {
background-color: #fff;
}
.read-button {
display: inline-block;
width: 230px;
height: 45px;
border: 1px solid #6b0;
color: #6b0;
vertical-align: top;
font-size: 14px;
line-height: 45px;
cursor: pointer;
}
.read-button:hover{
background: #6b0;
border: 1px solid #6b0;
color: #fff;
}
事件绑定addEventListener和事件解除绑定removeEventListener的基本用法
上面是“js文章太长显示部分(百分比),点击按钮显示全部”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_14280.html
workflows工作流
图生图工作流:粉红色梦幻家园comfyui工作流
梦幻向日葵ComfyUI工作流
一只漂亮的孔雀的尾巴完全由披萨制成ComfyUI工作流
一群蚂蚁在路上忙碌着ComfyUI工作流
一个可爱的口袋妖怪ComfyUI工作流
Latent放大comfyui工作流
一个女孩骑着一辆生锈的现代摩托车
一幅3D农场游戏画面ComfyUI工作流
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

3D彩色卡片
css3搭积木叠加图形
3d文字动画效果
做一个好玩的时钟翻牌效果
3d空间行走效果
一个包含老黄历、佛历、道历、星宿等数据的日历网站
纯CSS饼图效果
javascript如何利用draggable实现一个拖拽效果










