Skip to content

Instantly share code, notes, and snippets.

@marcosbrasil
Created July 17, 2012 14:47
Show Gist options
  • Save marcosbrasil/3129837 to your computer and use it in GitHub Desktop.
Save marcosbrasil/3129837 to your computer and use it in GitHub Desktop.
Simple extend jquery plugin for load images into DOM
var cache = [];
// Arguments are image absolute paths to the current page
$.preLoadImages = function(arrImg,funcCallback) {
var imgLen = arrImg.length;
for (var i = imgLen; i>=0 ;i--) {
if(typeof arrImg[i] !== 'undefined'){
var cacheImage = document.createElement('img');
cacheImage.src = arrImg[i];
cache.push(cacheImage);
}
}
// calling the callback
if(typeof funcCallback == 'function'){
return funcCallback.call(this);
}
}
//Relly simple exemple
var arrImage = ["http://urlimg1","http://urlimg1","http://urlimg..N"];
jQuery.preLoadImages(arrImage, function(){
console.log('Function Callback');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment