Preloading of images

//Picture preload 
function YReload(result,imgName,callBack){
var imgArr = [];
for(var i in result){
(function(item,src){
if(IsPicture(src)){//Get the picture path
imgArr[i] = new Image();
imgArr[i].src = src;
imgArr[i].onload = function(){
callBack(item);
};
}
})(result[i],result[i ][imgName]);
}

}

//Determine whether it is a picture
function IsPicture(str)
{
//Determine whether it is a picture - strFilter must be a lowercase list
var strFilter=".jpeg|.gif|.jpg|.png|.bmp |.pic|"
if(str.indexOf(".")>-1)
{
return true;
var p = str.lastIndexOf(".");
var strPostfix=str.substring(p,this.length) + '|';
strPostfix = strPostfix.toLowerCase();
if(strFilter.indexOf(strPostfix)>-1)
{
return true;
}
}
return false;
}

//调用
var result = success.data.data.list
YReload(result,'videoAudioLogo',function(item){
that.learningContent.push(item)
});

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324716922&siteId=291194637