Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
An example of imagesLoaded's cache behavior
/*
* An example of imagesLoaded's cache behavior
* see http://jsfiddle.net/FVLbn/2/
*/
var imgUrls = ['http://3.bp.blogspot.com/-K07eebumZmc/TvN1SmVvZvI/AAAAAAAACUI/TtxP5n9aL4w/s1600/strenco_steam_robot_1.jpg', 'http://www.warcrafthuntersunion.com/wp-content/uploads/2011/07/robot1.jpg','http://4.bp.blogspot.com/-il7IWW4_nyA/T5qojE8_FYI/AAAAAAAAC7M/D7mQZVkA4a8/s1600/nod32robot.png', 'http://neuronmnit.org/wp-content/uploads/2011/08/1312290130-21.jpg']
var images,
image1 = $('<img />').attr('src', imgUrls[0]),
image2 = $('<img />').attr('src', imgUrls[1]),
image3 = $('<img />').attr('src', imgUrls[2]),
image4 = $('<img />').attr('src', imgUrls[3]);
images = [image1, image2];
$(images).imagesLoaded(function(){
console.log('image1 and image2 loaded');
})
images = [image2, image3];
$(images).imagesLoaded(function(){
console.log('image2 and image3 loaded');
});
images = [image1, image2];
$(images).imagesLoaded(function(){
console.log('image1 and image2 loaded again');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment