zoukankan      html  css  js  c++  java
  • 图片未完成加载显示loading

    <html>
    <title>js图片未加载完显示loading效果</title>
    <body>
    <style>
    img{float:left;200px;height:200px;margin:0 10px 10px 0}
    </style>
    <script>
    //判断浏览器
    var Browser=new Object();
    Browser.userAgent=window.navigator.userAgent.toLowerCase();
    Browser.ie=/msie/.test(Browser.userAgent);
    Browser.Moz=/gecko/.test(Browser.userAgent);
    
    //判断是否加载完成
    function Imagess(url,imgid,callback){
        var val=url;
        var img=new Image();
        if(Browser.ie){
            img.onreadystatechange =function(){
                if(img.readyState=="complete"||img.readyState=="loaded"){
                    callback(img,imgid);
                }
            }
        }else if(Browser.Moz){
            img.onload=function(){
                if(img.complete==true){
                    callback(img,imgid);
                }
            }
        }
        //如果因为网络或图片的原因发生异常,则显示该图片
        img.onerror=function(){img.src="http://www.86y.org/images/failed.png"}
        img.src=val;
    }
    
    //显示图片
    function checkimg(obj,imgid){
    document.getElementById(imgid).style.cssText="";
    document.getElementById(imgid).src=obj.src;
    }
    //初始化需要显示的图片,并且指定显示的位置
    window.onload=function(){
    var imglist=document.getElementById("imagelist").getElementsByTagName('img');
    for(i=0;i<imglist.length;i++)
    {
        imglist[i].id="img0"+i;
        imglist[i].style = "background:url(http://www.86y.org/images/loading.gif) no-repeat center center;";
        Imagess(imglist[i].getAttribute("data"),imglist[i].id,checkimg);
    }
    }
    </script>
    <div id="imagelist">
    <img data="http://www.smashingapps.com/wp-content/uploads/2013/05/uikitsforwebmobile17s.jpg" />
    <img data="http://www.smashingapps.com/wp-content/uploads/2013/05/uikitsforwebmobile13.jpg" />
    <img data="http://www.smashingapps.com/wp-content/uploads/2013/05/uikitsforwebmobile39.jpg" />
    <img data="http://www.smashingapps.com/wp-content/uploads/2013/05/uikitsforwebmobile10.jpg" />
    <img data="http://www.smashingapps.com/wp-content/uploads/2013/05/uikitsforwebmobile14.jpg" />
    </div>
    </body>
    </html>
    

      

  • 相关阅读:
    wzplayer for android V1.5 整合硬解码(仍然支持加密音视频)
    mac osx 快捷键
    从零开始学AS3游戏开发【七】永无终结,不断完善的游戏
    flash flex as3 类库 资料大全
    php include一个有全局变量的应注意
    MySQL事件调度器 CREATE EVENT
    The Miner – 专业Flash AS3性能分析器(profiler)入门教程
    as3加密入门1使用alchemy进行代码混淆
    从零开始学AS3游戏开发【五】 告别方块,添加碰撞
    PHP实现的Mysql读写分离
  • 原文地址:https://www.cnblogs.com/tianwengao/p/6839722.html
Copyright © 2011-2022 走看看