js获取页面加载过程做一个简单的loading

3 篇文章 0 订阅
前几天写了一个简单的,还是觉得稍微改得像一点 大笑
document.onreadystatechange = loadingChange;//当页面加载状态改变的时候执行这个方法.  
        function loadingChange()   
        {   
            if(document.readyState == "complete"){//当页面加载状态为完全结束时进入   
                $(".process .cs").animate({width:"100%"},function(){
                     $(".loading").hide();//当页面加载完成后将loading页隐藏  
                     $('.wrap').show();
                });
            }   
        }   

<!DOCTYPE html>  
<html lang="zh">  
<head>  
    <meta charset="UTF-8">  
    <title>loading……demo</title>  
    <meta name="viewport" content="user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">  
<script type="text/javascript" src="js/jquery.js"></script>
</head>  
<body>  
    <div class="wrap" style="display: none;">  
        <section class="home">
           
        </section>  
    </div>  
    <div class="loading">  
         <div class="process">
             <div class="cs"></div>
         </div>
    </div> 
</body>  
</html>  

*{padding: 0; margin:0;}  
    html{font-size: 40px;}  
    body, html{width: 100%; height: 100%;}  
    .wrap{ position: relative; width:100%; height:100%;}  
    .home{width: 100%; height:100%; background: url(bg.jpg) no-repeat; background-size: 100% 100%;}  
    .loading{position: absolute; width: 100%; height: 100%; background: #fff; z-index: 99;}  
    .loading p{position: fixed; left: 50%; top: 50%; -webkit-transform: translate(-50%,-50%); text-align: center; color: #222; font-size:0.8rem;}
   .loading .process{ position: absolute;
        top: 50%; left: 50%; -webkit-transform:translate(-50%,-50%);
        width: 90%; height: 30px;
        border-radius: 3px;
        border: 1px solid #ccc;
        background: #fff;
        overflow: hidden;
    }
     .loading .process .cs{background: #899; width:0%; height: 100%;}


  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值