Skip to content

Instantly share code, notes, and snippets.

@rlemon
Created May 10, 2013 19:47
Show Gist options
  • Save rlemon/5556905 to your computer and use it in GitHub Desktop.
Save rlemon/5556905 to your computer and use it in GitHub Desktop.
image preloader
function preload(list, callback, imageCallback) {
var at = len = list.length;
return list = list.map(function (item) {
var pItem = new Image();
pItem.onload = function (i) {
imageCallback && imageCallback.call(this, this, len-at, len);
if (!--at) {
callback(list);
}
};
pItem.src = item;
return pItem;
});
}
function preload(l,c,i){var a=b=l.length;return l=l.map(function(t){var p=new Image;p.onload=function(){i&&i.call(this,this,b-a,b);!--a&&c(l)};p.src=t;return p})};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment