Categories
Software and Programming

image preloading hack

Found on the JQuery mailing list, here’s a javascript hack to preload hidden images to a webpage, by Luke Lutman – (this is just a quick note for myself)

$(window).bind('load', function(){
var preload = [
'/images/assets/file/1.gif',
'/images/assets/file/2.gif',
'/images/assets/file/3.gif'
];
$(document.createElement('img')).bind('load', function(){
if(preload[0]) this.src = preload.shift();
}).trigger('load');
});