Last active
December 14, 2015 15:29
-
-
Save fer-ri/5108367 to your computer and use it in GitHub Desktop.
jQuery Simple Preload Images
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(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