jquery预加载图片的方法
本文实例讲述了jquery预加载图片的方法。分享给大家供大家参考。具体如下:
这段代码可以在页面打开前对图片进行预加载,这个函数非常有用,可以给用户带来更好的体验。
functionpreloadImages(oImageList,callback){
if(typeof(oImageList)=='object'&&typeof(callback)==="function"){
variCallbackAfter=oImageList.length;
variPreloadInterval=window.setInterval(function(){
if(iCallbackAfter===0){
window.clearInterval(iPreloadInterval);
callback();
}
},100);
$.each(oImageList,function(iIndex,sImage){
oImageList[iIndex]=newImage();
oImageList[iIndex].onload=function(oResult){
iCallbackAfter--;
};
oImageList[iIndex].onabort=function(oResult){
console.log(oResult);
};
oImageList[iIndex].onerror=function(oResult){
console.log(oResult);
};
if(!sImage.match('http://')){
sImage=sImage;
}
oImageList[iIndex].src=sImage;
});
}
}
希望本文所述对大家的jQuery程序设计有所帮助。
热门推荐
10 新年祝福语鼠年简短创意
11 交个朋友蛋糕祝福语简短
12 简短有深度的祝福语
13 鸡脚结婚祝福语大全简短
14 分别祝福语简短情话英文
15 客户十一祝福语大全 简短
16 10岁高考祝福语简短
17 恭喜生孩子祝福语简短
18 拜年年祝福语大全简短