预加载2+网页加载条 可以直接复制代码运行,如果图片地址丢失的话可以自己替换掉

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
        *{ margin:0; padding:0;}
        ul{list-style: none;}
        #progressBox{ width:300px; height:40px; border:1px solid #C8C8C8; background:white; position:relative; margin:200px auto;}
        #progressBar{ position:absolute; left:0; top:0; z-index:2; height:40px; width:100%; line-height:40px; color:white; text-align:center; font-size:20px; font-weight:bold; font-family:Georgia; clip:rect(0px, 0, 40px, 0px); background:#00A1F5;}
        #progressText { position:absolute; left:0; top:0; z-index:1; width:100%; height:40px; line-height:40px; color:black; text-align:center; font-size:20px; font-weight:bold; font-family:Georgia;}
        #imgList{display: none;}
        body{width:100%;}
        ul{width:100%;}
        img{display: block;width:100%;height:100%;}
    </style>

</head>
<body>
<div id="progressBox">
    <div id="progressBar">0%</div>
    <div id="progressText">0%</div>
</div>

<ul id="imgList"></ul>


<script type="text/javascript">
    var imgs=["http://www.wallcoo.com/nature/da_ps_landscape_01/wallpapers/1680x1050/%5Bwallcoo_com%5D_April_23rd.jpg",
    "http://pic5.bbzhi.com/chuangyibizhi/zuixinchuangyishejibizhi/zuixinchuangyishejibizhi_415791_11.jpg",
    "http://img.bz1111.com/d3/2010-10/2010103021073576056.jpg",
    "http://www.pp3.cn/uploads/20120627gj/bz_gj_05.jpg",
            "http://www.onegreen.net/Article/UploadFiles/200811/2008111874946653.jpg",
            "http://lib.nit.net.cn/dlib/resource/jpg/1889.jpg",
            "http://www.lwdx.cn/UploadFiles/Photo/2009/2/bizhi/stzw20081005/stzw20081005_001.jpg"
    ];



    var ul1= document.getElementById('imgList');
    var oDiv1 = document.getElementById('progressBox');
    var oDiv2 = document.getElementById('progressBar');
    var oDiv3 = document.getElementById('progressText');

    var iNow=0;


    for(var i=0;i<imgs.length;i++)
    {
       (function(n){


            var yImg=new Image();
            yImg.src=imgs[i];
            yImg.οnlοad=function()
            {
                var dd=document.createElement("li");
                dd.innerHTML="<img src='"+yImg.src+"'/>";
                ul1.appendChild(dd);
                iNow++;
               // alert(i);
                progressFn(parseInt(iNow/(imgs.length-1) * 100));
                if(iNow==(imgs.length-1)){
                    oDiv2.style.display = 'block';
                    ul1.style.display="block";
                    oDiv1.style.display = 'none';
                }
            };
        }(i));


        function progressFn(cent){//网页加载条
            var allWidth = parseInt(getStyle(oDiv1,'width'));


            oDiv2.innerHTML = cent + '%';
            oDiv3.innerHTML = cent + '%';
            oDiv2.style.clip = 'rect(0px, '+ cent * (allWidth/100) +'px, 40px, 0px)';


            function getStyle(obj,attr){//获取样式,兼容
                if(obj.currentStyle){
                    return obj.currentStyle[attr];
                }
                else{
                    return getComputedStyle(obj)[attr];
                }
            }


        }
}


</script>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

陆康永

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值