-
-
Save ncou/ed47a7d23c5fec4a8fb7a375a8e492eb to your computer and use it in GitHub Desktop.
image preloader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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