【css系列】创建网页加载进度条

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

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>
				
时间: 2024-08-02 11:02:50

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

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

今天给大家带来一个比较炫的进度条,进度条在一耗时操作上给用户一个比较好的体验,不会让用户觉得在盲目等待,对于没有进度条的长时间等待,用户会任务死机了,毫不犹豫的关掉应用:一般用于下载任务,删除大量任务,网页加载等:如果有使用html5为手机布局的,也可以用于手机中~ 效果图: 1.html结构: <div id="loadBar01" class="loadBar"> <div> <span class="percent&qu

Chromium中网页加载进度条研究

1.     Shell.java中有成员变量:mProgressDrawable. 该成员变量在方法:onFinishInflate中被初始化. 在该类中有方法:onLoadProgressChanged,该方法中对进度条的值进行改变,并且对刷新完成事件进行反馈. 2.     上面的这个方法是在cc文件中被调用的. 上面方法对应的cc方法是shell_android.cc文件中的LoadProgressChanged方法. voidShell::LoadProgressChanged(Web

网页加载进度条

( 网页加载时,有时内容过多,一直加载等待,而此时网页显示白色不显示任何的东西,给用户的体验相当不好,所以,一般会在网页加载成功前,会以进度条的形式,给用户进行展示.让用户可以看到动画,知道网页正在加载中) 常见的方式有以下: 1. 定时器的进度条(假的) <script type="text/javascript">     $(function(){         var loading='<div class="loading">&l

网页加载进度条的实现

本次主要介绍一下网页加载进度的实现.如下图,在页面加载的时候,上方红色的进度条 网页加载进度的好处是能够更好的反应当前网页的加载进度情况,loading进度条可用动画的形式从开始0%到100%完成网页加载这一过程.但是目前的浏览器并没有提供页面加载进度方面的接口,也就是说页面还无法准确返回页面实际加载的进度,本文中我们使用jQuery来实现页面加载进度条效果. 首先我们要知道的是,目前没有任何浏览器可以直接获取正在加载对象的大小.所以我们无法通过数据大小来实现0-100%的加载显示过程. 因此我

网页加载进度条的JS程序开发思路与实际应用

一款好的产品,都需要有一个漂亮的loading界面.lodaing界面不仅能给用户带来良好的体验,而且有效的消除了程序加载等待过程中的枯躁感. loading进度条更是对当前加载进度的一个良好反馈.从0%-100%的加载进度可以有效的告知用户还有多久即可打开页面.带有进度条的loading界面在程序中并不罕见,但是在web中呢?到目前为止浏览器并没有提供有效的浏览器对象来反馈页面的加载进度,所以无法直接.便捷的获得页面加载进度的反馈.本文主要是讲述如何以通过jquery的方式来实现页面加载进度的

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

一.效果展示 WKWebProgressViewDemo.gif 二.主要步骤 1.添加UIProgressView属性 @property (nonatomic, strong) WKWebView *wkWebView; @property (nonatomic, strong) UIProgressView *progressView; 2.初始化progressView - (void)viewDidLoad { [super viewDidLoad]; //进度条初始化 self.pr

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

首先先是吐槽时间... 告诉大家一个好消息,就是有个妹子非常仰慕我的前端技术说要包养我 然后有好多羡慕嫉妒恨的童鞋一定要说,少年你太天真了,那一定是HR 然后我表示她不是HR,本宅的春天貌似要到来了...T_T,25年的单身生涯.终于走到了尽头......然后妹子也是前端...为了保证光辉形象.我必要努力提升技术 然后么今天闲的蛋疼,再看看一帮大牛们的装逼网站,然后无意间看到这一段,只想说大牛们的世界真会玩.... 利用图片上data,还有load 最后在用document.readyState

webview添加网页加载进度条

最近在android项目中使用webview嵌套了一个抽奖活动网页,活动上线,运行良好(改了N次需求和突发bug),还好这种模式的活动,只需要修改网页,不需要重新打包发布市场,这也是这种模式开发的优势之一.后来据产品哥反馈说加载网页无进度提示,好吧,这个当时真没考虑这么多,这个要加加..想当然以为轻松搞定之....其实还是比轻松要复杂点... 1.首先自定义一个WebView控件 1 /** 2 * 带进度条的Webivew 3 * @author [email protected] 4 */

网页加载进度条中的javascript

demo地址:http://output.jsbin.com/buquyedosa 思路如下:代码都有注释,就不一一介绍了. <!DOCTYPE html> <html> <head lang="zh-cn"> <meta charset="UTF-8"> <title>进度条</title> <style> .progress{ position: fixed; top: 0; r