css3实现loading效果--当页面加载过程中显示Loading的进度条,全部加载完成之后进度条消失
一个页面等图片资源全部加载完成,会需要很长时间,用户体验会很差,所以我们需要loading来掩盖这个漫长的过程!
emmm,定时器?写个定时器还要清除,万一造成内存泄露?定时器之间还会互相影响,呼呼呼那就不考虑了
那么就用css写一个~~
语法:
animation: name duration timing-function delay iteration-count direction;
@keyframes 规则用于创建动画。在 @keyframes 中规定某项 CSS 样式,就能创建由当前样式逐渐改为新样式的动画效果。
1、设置进度条起始宽度0%,3s之内宽度移动85%,为什么不设置100%呢? 因为3s进度条就加载到100%,如果我们的页面却迟迟没有加载完成,那么完全影响用户体验,所以我们设置到85%就让进度条停了下来,然后页面加载完成之后隐藏进度条,实现以假乱真!
/* loading */
.loading {
background: #000;
position: absolute;
z-index:;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
.progress {
position: relative;
width: 200px;
height: 8px;
background: #fff;
border-radius: 20px;
margin-top: 20px;
}
.progress-bar {
position: absolute;
left:;
top:;
height: 8px;
line-height: 20px;
border-radius: 20px;
background: #d7bb29;
animation: animate-positive 3s;
}
@keyframes animate-positive {
from {width:0px;}
to {width:85%;}
}
@-webkit-keyframes animate-positive {
from {width:0px;}
to {width:85%;}
}
2.js判断页面是否加载完成,使用一个document 的 Document.readyState 属性描述了文档的加载状态。complete / 完成文档和所有子资源已完成加载。表示 load状态的事件即将被触发
当document.readyState == "complete",表示页面所有内容已被完全加载此时可以隐藏loading
var loading = document.getElementById("loading");
if (document.readyState == "complete") {
// 页面加载完毕
loading.style.display = "none";
}
3.附上demo
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>loading</title>
<style>
/* loading */
.loading {
background: #000;
position: absolute;
z-index: 999;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
.progress {
position: relative;
width: 200px;
height: 8px;
background: #fff;
border-radius: 20px;
margin-top: 20px;
}
.progress-bar {
position: absolute;
left: 0;
top: 0;
height: 8px;
line-height: 20px;
border-radius: 20px;
background: #d7bb29;
animation: animate-positive 3s;
}
@keyframes animate-positive {
from {width:0px;}
to {width:85%;}
}
@-webkit-keyframes animate-positive {
from {width:0px;}
to {width:85%;}
} </style>
</head>
<body>
<div id="loading" class="loading">
<div class="progress">
<div class="progress-bar">
</div>
</div>
</div>
<script>
var loading = document.getElementById("loading");
if (document.readyState == "complete") {
// 页面加载完毕 // loading.style.display = "none";
}
</script>
</body>
</html>
4.效果图如下,可根据自己需求修改样式,已经进度条进度时间,进度曲线等~~

css3实现loading效果--当页面加载过程中显示Loading的进度条,全部加载完成之后进度条消失的更多相关文章
- 在程序加载过程中显示ProgressDialog 对话框
private ProgressDialog mProgressDlg = null; @Override protected void onCreate(Bundle savedInstanceSt ...
- 在页面未加载完之前显示loading动画
在页面未加载完之前显示loading动画 这里有很多比这篇博客还优秀的loading动画源码 我还参考这篇博客 loading动画代码demo 我的demo预览 <!DOCTYPE html&g ...
- vue项目未加载完成前显示loading...
1.在Index.html里面加入loading的元素,让loading元素显示,让app元素隐藏 <!DOCTYPE html> <html> <head> &l ...
- jquery Ajax请求中显示Loading...
jquery Ajax请求中显示Loading... $('#btnTest').click(function(){ $.ajax({ url ---- ,根据你需要设置 ...
- ZOJ 3962 Seven Segment Display 16进制的八位数加n。求加的过程中所有的花费。显示[0,F]有相应花费。
Seven Segment Display Time Limit: Seconds Memory Limit: KB A seven segment display, or seven segment ...
- Javascript在ajax提交过程中页面显示加载中,请等待效果,并在提交过程中限制确定按钮防止多次提交,提交完成后,解除提交限制
加载中,请等待div: <div id="load" class="center-in-center" style="display:none; ...
- jquery加载数据时显示loading加载动画特效
插件下载:http://www.htmleaf.com/jQuery/Layout-Interface/201505061788.html 插件使用: 使用该loading加载插件首先要引入jQuer ...
- DOM加载过程中ready和load的区别
在浏览器地址栏输入URL地址,浏览器开始加载页面时,有以下几个过程 1.浏览器开始解析HTML文档 2. 浏览器遇到HTML文档中的<script>元素以及CSS样式文件,并且没有asyn ...
- js 页面按钮提交后 创建显示loading div 操作完成后 再隐藏或删除 进度div
预期效果: 1.点击Save按钮,创建及显示loading div框 2.Save操作完成后,再删除loading 及弹出提示结果 <html> <head> </hea ...
随机推荐
- mysql中id值被重置的情况
MySQL中,如果你为一张使用了innodb引擎的表指定了一auto_increment列,那么这张表会有一个auto_increment计数器,专门记录当前auto_increment的相关值,用来 ...
- centos 5.2 php升级
# gedit /etc/yum.repos.d/utterramblings.repo [utterramblings] name=Jason's Utter Ramblings Repo base ...
- 20141111-WCF获得Web路径
在WCF中调用Server.MapPath 获取服务发布目录路径 在WCF中调用Server.MapPath 获取服务发布目录路径 在WCF中想使用Server.Map获取当前服务发布目录的绝对路径. ...
- Kafka部署
Kafka依赖Zookeeper,虽然Kafka自带zookeeper,但是建议单独部署,所以先部署Zookeeper. 测试环境 citus1,citus2,citus3三台机器.对主机名和ip在/ ...
- 2017-10271weblogic漏洞exp测试及补丁测试
靶机:weblogic12.1.3.0 战斗机:kali 导弹:burpsuite 1.首先开启kali某端口监听 2.向靶机发送exp 3.查看kali监听 打码保平安~~ 4.打上补丁 5.验证补 ...
- golang开发:类库篇(四)配置文件解析器goconfig的使用
为什么要使用goconfig解析配置文件 目前各语言框架对配置文件书写基本都差不多,基本都是首先配置一些基础变量,基本变量里面有环境的配置,然后通过环境变量去获取该环境下的变量.例如,生产环境跟测试环 ...
- python基础一整型、bool、字符串
1整型.bool.字符串 1.整型 --数字(int) 用于比较运算的 32位 -2 ** 31 ~ 2 ** 31 -1 64位 -2 ** 63 ~ 2 ** 63 -1 基础运算 ...
- Excel导出功能超时解决方案 -- 异步处理
背景 有运营同学反馈,最近导出excel会出现超时的情况,初步判断是数据增长太快,数据量太大,请求时间超过了设置的超时时间 尝试 有考虑直接更改该请求的超时时长,可是治标不治本 网上搜索发现,有很多人 ...
- 理解 Spring 定时任务的 fixedRate 和 fixedDelay 的区别
用过 Spring 的 @EnableScheduling 的都知道,有三种方式,即 @Scheduled 注解的 fixedRate(fixedRateString), fixedDelay(fix ...
- Java 多线程部分面试题
1..什么是线程,什么是进程,它们有什么区别和联系,一个进程里面是否必须有个线程 进程和线程的主要差别在于它们是不同的操作系统资源管理方式.进程有独立的地址空间,一个进程崩溃后,在保护模式下不会对其它 ...