Skip to content

Instantly share code, notes, and snippets.

@JackDanger
Created April 10, 2009 05:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JackDanger/92951 to your computer and use it in GitHub Desktop.
Save JackDanger/92951 to your computer and use it in GitHub Desktop.
simple framework-agnostic javascript image preloader
// USAGE:
// preloadImage('/images/something_over.png')
// preloadImage('/images/other_over.gif')
// preloadImage.load()
preloadImage = (function(){
var images = []
var placeholder = new Image()
var instantiate = function(idx){
if(!images[idx]) return
placeholder.src = images[idx]
setTimeout( function(){ instantiate(idx+1) }, 25)
}
callable = function(){
for(var i=0, length = arguments.length; i < length; i++ )
images[images.length] = arguments[i]
}
callable.load = function(){
instantiate(0)
}
return callable;
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment