Skip to content

Instantly share code, notes, and snippets.

@bretdavidson
Created April 30, 2014 18:06
Show Gist options
  • Save bretdavidson/66c8f54faf5027a7ea93 to your computer and use it in GitHub Desktop.
Save bretdavidson/66c8f54faf5027a7ea93 to your computer and use it in GitHub Desktop.
// Taken from: http://stackoverflow.com/a/476681
(function() {
var arrayOfImages = ["one.jpg", "two.jpg", "three.jpg"];
function preload(arrayOfImages) {
$(arrayOfImages).each(function () {
$('<img/>')[0].src = this;
});
}
//Usage:
preload(arrayOfImages);
}());
// Or as a jQuery plugin
(function () {
$.fn.preload = function() {
this.each(function(){
$('<img/>')[0].src = this;
});
};
// Usage:
$(['one.jpg','two.jpg','three.jpg']).preload();
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment