Skip to content

Instantly share code, notes, and snippets.

@ncou
Forked from rlemon/preloader.js
Created August 6, 2017 09:17
Show Gist options
  • Save ncou/ed47a7d23c5fec4a8fb7a375a8e492eb to your computer and use it in GitHub Desktop.
Save ncou/ed47a7d23c5fec4a8fb7a375a8e492eb 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