Preload images with jQuery

$(function(){
    var cache = []; // declare array to store our images
    $.preLoadImages = function(){
        var args_len = arguments.length;
        for(var i = args_len; i--;){
            var cacheImage = document.createElement('img');
            cacheImage.src = arguments[i];
            cache.push(cacheImage);
        }
    };
 }); // call our predefined function $.preLoadImages('./images/sample1.png', './images/sample2.png'); 

Reference:

http://engineeredweb.com/blog/09/12/preloading-images-jquery-and-javascript/

Advertisements

One thought on “Preload images with jQuery

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s