Skip to content

Instantly share code, notes, and snippets.

@fer-ri
Last active December 14, 2015 15:29
Show Gist options
  • Save fer-ri/5108367 to your computer and use it in GitHub Desktop.
Save fer-ri/5108367 to your computer and use it in GitHub Desktop.
jQuery Simple Preload Images
function preload(arrayOfImages) {
$(arrayOfImages).each(function(){
$('<img />').attr('src',this).appendTo('body').hide();
});
}
// Usage:
preload([
'img/imageName.jpg',
'img/anotherOne.jpg',
'img/blahblahblah.jpg'
]);
$("#content img").on("click",function(){ // use .live instead if you are using an older version of jQuery
var next = $(this).next();
for (var i = 0; i < 3; i++)
{
var img = new Image();
img.src = next.attr("alt");
next = next.next();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment