Skip to content

Instantly share code, notes, and snippets.

@pierre-b
Created December 19, 2014 23:02
Show Gist options
  • Save pierre-b/880eae0ce72848774747 to your computer and use it in GitHub Desktop.
Save pierre-b/880eae0ce72848774747 to your computer and use it in GitHub Desktop.
Javascript image preload
var preloadImage = function(src, callback){
var img = new Image();
img.src=src;
img.onload = function(){
callback();
}
};
// usage
preloadImage(path, function(){
console.log('image loaded, do more stuff here');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment