一、最简单或者明显的方式是使用定时器

1、在网页中加入布局覆盖真实网页内容

2、使用定时器确定加载所用时间的长短,其实并不是真正的加载进度实现

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>定时器的进度条</title>
<script src="../js/jquery-3.2.1.js"></script>
<script type="text/javascript">
$(function () {
setInterval(function () {
$(".loading").fadeOut();
},3000)
})
</script>
<style type="text/css">
.loading{
width: 100%;
height: 100%;
position: fixed;
top:0;
left:0;
z-index: 100;
background-color: white;
}
.loading .pic{
width: 64px;
height: 64px;
border: 1px solid red;
background: url("./image/35.gif");
position: absolute;
top:0;
bottom: 0;
left: 0;
right:0;
margin: auto; }
</style>
</head>
<body>
<div class="loading">
<div class="pic"></div>
</div>
<img src="https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=2374531200,2817019640&fm=11&gp=0.jpg" alt=""/>
<img src="https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1019761374,1197310851&fm=26&gp=0.jpg"/>
<img src="https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1091681404,1813447708&fm=26&gp=0.jpg">
<img src="https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=4039520080,1420114353&fm=26&gp=0.jpg"/>
</body>
</html>

二、在第一版中做改良

1、理论上还是使用定时器

2、覆盖的内容不在布局中定义而是动态加载

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>定时器的进度条</title>
<script src="../js/jquery-3.2.1.js"></script>
<script type="text/javascript">
$(function () {
var loading = '<div class="loading"><div class="pic"></div></div>';
$("body").append(loading);
setInterval(function () {
$(".loading").fadeOut();
},3000)
})
</script>
<style type="text/css">
.loading{
width: 100%;
height: 100%;
position: fixed;
top:0;
left:0;
z-index: 100;
background-color: white;
}
.loading .pic{
width: 64px;
height: 64px;
border: 1px solid red;
background: url("./image/35.gif");
position: absolute;
top:0;
bottom: 0;
left: 0;
right:0;
margin: auto; }
</style>
</head>
<body>
<div class="loading">
<div class="pic"></div>
</div>
<img src="https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=2374531200,2817019640&fm=11&gp=0.jpg" alt=""/>
<img src="https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1019761374,1197310851&fm=26&gp=0.jpg"/>
<img src="https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1091681404,1813447708&fm=26&gp=0.jpg">
<img src="https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=4039520080,1420114353&fm=26&gp=0.jpg"/>
</body>
</html>

三、通过加载状态实现进度条

document.onreadystatechange   页面加载状态改变时的事件
document.readyState 返回当前文档的状态
uninitialized:还未开始载入
loading:载入中
interactive已加载。文档与用户可以开始交互
complete:载入完成
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>进度条</title>
<style type="text/css">
.loading{
width: 100%;
height: 100%;
position: fixed;
top:0;
left:0;
z-index: 100;
background-color: white;
}
.loading .pic{
width: 64px;
height: 64px;
border: 1px solid red;
background: url("./image/35.gif");
position: absolute;
top:0;
bottom: 0;
left: 0;
right:0;
margin: auto; }
</style>
<script src="../js/jquery-3.2.1.js"></script>
<script type="text/javascript">
document.onreadystatechange = function () {
console.log(document.readyState);
if(document.readyState=='complete'){
$(".loading").fadeOut();
}
}
</script>
</head>
<body>
<div class="loading">
<div class="pic"></div>
</div>
<img src="https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=2374531200,2817019640&fm=11&gp=0.jpg" alt=""/>
<img src="https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1019761374,1197310851&fm=26&gp=0.jpg"/>
<img src="https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1091681404,1813447708&fm=26&gp=0.jpg">
<img src="https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=4039520080,1420114353&fm=26&gp=0.jpg"/>
</body>
</html>

四、使用css创建进度条动画

1、我们可以在https://loading.io/网站上生成css动画图或者获得动画的css样式自己使用

2、我们可以在https://autoprefixer.github.io/?中自动做css的兼容

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>css3创建动画</title>
<style type="text/css">
.loading{
width: 100%;
height: 100%;
position: fixed;
top:0;
left:0;
z-index: 100;
background-color: white;
}
.loading .pic{
width: 50px;
height: 50px;
position: absolute;
top:0;
bottom: 0;
left: 0;
right:0;
margin: auto; }
.loading .pic i{
display: block;
float: left;
width: 6px;
height: 50px;
background: #399;
margin: 0 2px;
-webkit-transform: scaleY(0.4);
-ms-transform: scaleY(0.4);
transform: scaleY(0.4);
-webkit-animation: load 1.2s infinite;
animation: load 1.2s infinite;
}
.loading .pic i:nth-child(1){ }
.loading .pic i:nth-child(2){
-webkit-animation-delay: 0.1s;
animation-delay: 0.1s;
}
.loading .pic i:nth-child(3){
-webkit-animation-delay: 0.2s;
animation-delay: 0.2s;
}
.loading .pic i:nth-child(4){
-webkit-animation-delay: 0.3s;
animation-delay: 0.3s;
}
.loading .pic i:nth-child(5){
-webkit-animation-delay: 0.4s;
animation-delay: 0.4s;
}
@-webkit-keyframes load {
0%,40%,100%{-webkit-transform: scaleY(0.4);transform: scaleY(0.4)}
20%{-webkit-transform: scaleY(1);transform: scaleY(1)}
}
@keyframes load {
0%,40%,100%{-webkit-transform: scaleY(0.4);transform: scaleY(0.4)}
20%{-webkit-transform: scaleY(1);transform: scaleY(1)}
}
</style>
<script src="../js/jquery-3.2.1.js"></script>
<script type="text/javascript">
document.onreadystatechange = function () {
if(document.readyState == "complete"){
$(".loading").fadeOut();
}
}
</script>
</head>
<body>
<div class="loading">
<div class="pic">
<i></i>
<i></i>
<i></i>
<i></i>
<i></i>
</div>
</div>
<img src="https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=2374531200,2817019640&fm=11&gp=0.jpg" alt=""/>
<img src="https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1019761374,1197310851&fm=26&gp=0.jpg"/>
<img src="https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1091681404,1813447708&fm=26&gp=0.jpg">
<img src="https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=4039520080,1420114353&fm=26&gp=0.jpg"/>
</body>
</html>
												

【css系列】创建网页加载进度条的更多相关文章

  1. 用document.readyState实现网页加载进度条

    概述 之前以为给网页设置加载进度条很麻烦,今天一学真是超级简单,记录下来供以后开发时参考,相信对其他人也有用. readyState 主要运用了document.readyState和nprogres ...

  2. HTML5 CSS3 诱人的实例 : 网页加载进度条的实现,下载进度条等

    今天给大家带来一个比较炫的进度条,进度条在一耗时操作上给用户一个比较好的体验,不会让用户觉得在盲目等待,对于没有进度条的长时间等待,用户会任务死机了,毫不犹豫的关掉应用:一般用于下载任务,删除大量任务 ...

  3. iOS WKWebView添加网页加载进度条(转)

    一.效果展示 WKWebProgressViewDemo.gif 二.主要步骤 1.添加UIProgressView属性 @property (nonatomic, strong) WKWebView ...

  4. Jquery网页加载进度条(随笔,当然要随便写,当日记动态心情写咯)

    首先先是吐槽时间... 告诉大家一个好消息,就是有个妹子非常仰慕我的前端技术说要包养我 然后有好多羡慕嫉妒恨的童鞋一定要说,少年你太天真了,那一定是HR 然后我表示她不是HR,本宅的春天貌似要到来了. ...

  5. jQuery网页加载进度条插件

    jquery.pace.js会自动监测你的Ajax请求,事件循环滞后,记录您的页面上准备状态和元素来决定的进度情况. 将pace.js和主题css的添加到您的网页! pace.js会自动监测你的Aja ...

  6. JS网页加载进度条

    参考:http://www.cnblogs.com/timy/archive/2011/12/07/2279200.html

  7. 混合开发(一)——WebView开发高级技巧之加载网页以及JavaScript,加载进度条

    混合开发(一)--WebView开发高级技巧之加载网页以及JavaScript,加载进度条 现在关于混合开发也越来越多了,很多人喜欢跟随,比如HB,比如RN,其实这东西很早就有这么一个概念了,而且说实 ...

  8. pace.js – 网页自动加载进度条插件

    网站顶部的页面加载进度条是怎么实现的,页面的加载进度百分比,有时候获取是比较麻烦的,当然也可以利用一些优秀的JavaScript插件来实现,今天就为大家介绍这样子的一款插件:pace.js. [官方网 ...

  9. 【原生JS插件】LoadingBar页面顶部加载进度条

    先展示一下已经实现的效果: 预览地址:http://dtdxrk.github.io/js-plug/LoadingBar/index.html 看到手机上的浏览器内置了页面的加载进度条,想用在pc上 ...

随机推荐

  1. (原)linux下利用cmake来编译jthread开源库

    其实上次在用hisi3531平台的时候,就已经编译过一次这个库了,这次换了平台环境,交叉编译器变成了arm-hisiv100-linux-工具链,所以,没办法只能重新来过. 因为之前编译过,所以这次还 ...

  2. [ACM] POJ 1611 The Suspects (并查集,输出第i个人所在集合的总人数)

    The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 21586   Accepted: 10456 De ...

  3. VS2013启动浏览器链接(BrowserLink),导致页面脚本错误和页面加载变慢

    页面脚本出错场景:

  4. linux cfs调度器

    在抽象模型中vruntime决定了进程被调度的先后顺序,在真实模型中决定被调度的先后顺序的参数是由函数entity_key决定的.   static inline s64 entity_key(str ...

  5. 【machine translate】deep learning seq2seq

    https://www.tensorflow.org/tutorials/seq2seq https://medium.com/@devnag/seq2seq-the-clown-car-of-dee ...

  6. nginx反向代理配置(nginx.conf+proxy_set_header)

    转载:https://blog.csdn.net/bjsunwei/article/details/62231209 location / { proxy_pass http://test; prox ...

  7. 如何在 CentOS 7 上安装 Docker

    Docker 是一个开源工具,它可以让创建和管理 Linux 容器变得简单.容器就像是轻量级的虚拟机,并且可以以毫秒级的速度来启动或停止.Docker 帮助系统管理员和程序员在容器中开发应用程序,并且 ...

  8. 设置js同源

    1)设置 document.domain 成一样的就行了(前提是都是同一个顶级域名) 2)例如,域名1:news.xxx.com ,域名2:member.xxx.com,这时可以设置它们的 docum ...

  9. 3. Oracle数据库逻辑备份与恢复

    一. Oracle逻辑备份介绍 Oracle逻辑备份的核心就是复制数据:Oracle提供的逻辑备份与恢复的命令有exp/imp,expdp/impdp.当然像表级复制(create table tab ...

  10. iOS开发-VFL初窥

    VFL是苹果为了简化Autolayout的编码而推出的抽象语言,在上一篇博客中我们发现如果使用NSLayoutConstraint来添加约束是非常繁琐的. 一个简单的Frame需要添加四个NSLayo ...