Simple jQuery Image Preloading
Again, this is more a note to myself, but I find the best function to preload images with jQuery is the following:
jQuery.preloadImages = function() {
for(var i = 0; i<arguments.length; i++)
{
jQuery("<img>").attr("src", arguments[i]);
}
}
This accepts X amount of arguments and can be called like the following:
$.preloadImages("/static/img/loadinganimation.gif", "/static/img/throbber.gif");
Why would you want to do this? Simple – if you’re using any “loading animations” on your site, with animated GIFs, you may find that on first activation on certain browsers the GIF is missing. If you preload it using a function like this one, your problem is solved.
Credit to this function goes to bloggingdeveloper.com.
