首页 > 代码库 > 图片未完成加载显示loading

图片未完成加载显示loading

<html><title>js图片未加载完显示loading效果</title><body><style>img{float:left;width: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=http://www.mamicode.com/val;"";document.getElementById(imgid).src=http://www.mamicode.com/obj.src;"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>

  

图片未完成加载显示loading