一个页面等图片资源全部加载完成,会需要很长时间,用户体验会很差,所以我们需要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的进度条,全部加载完成之后进度条消失的更多相关文章

  1. 在程序加载过程中显示ProgressDialog 对话框

    private ProgressDialog mProgressDlg = null; @Override protected void onCreate(Bundle savedInstanceSt ...

  2. 在页面未加载完之前显示loading动画

    在页面未加载完之前显示loading动画 这里有很多比这篇博客还优秀的loading动画源码 我还参考这篇博客 loading动画代码demo 我的demo预览 <!DOCTYPE html&g ...

  3. vue项目未加载完成前显示loading...

    1.在Index.html里面加入loading的元素,让loading元素显示,让app元素隐藏 <!DOCTYPE html> <html> <head> &l ...

  4. jquery Ajax请求中显示Loading...

    jquery Ajax请求中显示Loading... $('#btnTest').click(function(){      $.ajax({           url ---- ,根据你需要设置 ...

  5. 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 ...

  6. Javascript在ajax提交过程中页面显示加载中,请等待效果,并在提交过程中限制确定按钮防止多次提交,提交完成后,解除提交限制

    加载中,请等待div: <div id="load" class="center-in-center" style="display:none; ...

  7. jquery加载数据时显示loading加载动画特效

    插件下载:http://www.htmleaf.com/jQuery/Layout-Interface/201505061788.html 插件使用: 使用该loading加载插件首先要引入jQuer ...

  8. DOM加载过程中ready和load的区别

    在浏览器地址栏输入URL地址,浏览器开始加载页面时,有以下几个过程 1.浏览器开始解析HTML文档 2. 浏览器遇到HTML文档中的<script>元素以及CSS样式文件,并且没有asyn ...

  9. js 页面按钮提交后 创建显示loading div 操作完成后 再隐藏或删除 进度div

    预期效果: 1.点击Save按钮,创建及显示loading div框 2.Save操作完成后,再删除loading 及弹出提示结果 <html> <head> </hea ...

随机推荐

  1. Nginx+vsftpd

    一.安装Nginx 关闭selinux和firewalld setenforce sed -i 's/^SELINUX=enforcing$/SELINUX=disabled/' /etc/selin ...

  2. vue源码阅读(二)

    一 一个实例 如果简单了解过些Vue的API的话,肯定会对一下这个特别熟悉,在上一篇里,分析了Vue的核心文件core的index.js构造vue函数执行的流程. 那么下边这个则是实例化构造函数,也就 ...

  3. [原创]SSH Tunnel for UDP

    SSH Tunnel for UDP UDP port forwarding is a bit more complicated. We will need to convert the packet ...

  4. acm 模板

    Index 分类细则 说起分类准则,我也是很头疼,毕竟对于很多算法,他并不是单调的,而是多方面的都挂得上钩.所以,从始至终,分类准则一直都是我很纠结的问题. 经过思量,首先分出比较主流的几类:Numb ...

  5. [leetcode] 309. Best Time to Buy and Sell Stock with Cooldown(medium)

    原题 思路: 状态转移 出售股票的状态,最大利润有两种可能. 一,和昨天一样不动:二,昨天持有的股票今天卖掉. sell[i] = max(sell[i-1],buy[i-1] + prices[i] ...

  6. u盘制作启动盘步骤以及安装win10步骤

    1.下载制作工具:微PE工具箱V2.0 http://www.wepe.com.cn/download.html 2.默认制作启动盘 3.下载win10镜像 ed2k://|file|cn_windo ...

  7. Python_Day1_人人都爱列表

    列表由一系列按特定顺序排列的元素组成.你可以创建包含字母表中所有字母.数字0~9或 所有家庭成员姓名的列表;也可以将任何东西加入列表中,其中的元素之间可以没有任何关系. 鉴于列表通常包含多个元素,给列 ...

  8. jsp定义全局变量:读取properties文件

    <%java.util.Properties prop = new java.util.Properties();java.io.InputStream in;in = getClass().g ...

  9. webstorm mac 版破解

    一.打开终端,输入: sudo vim /etc/hosts 回车后输入密码,编辑 hosts 文件,如图: 二.进入编辑模式(按 i 键),在最后一行添加如下代码: 0.0.0.0 account. ...

  10. Python基础总结之第三天开始重新认识‘字符串’(新手可相互督促)

    年薪20万的梦想,又进了一步... 戏好多 ’字符串‘开始啦~ 字符串的定义:字符串可以用英文单引号或双引号又或者三引号包围起来. 为毛有单引号,还要有双引号和三引号??? 看案例吧: 字符串的其他使 ...