jQuery Image Preload »

0

Tags: jQuery

Was looking for a way to preload images and display some sort of loader. This small snippet is the functionality to do, the onload callback enables extra functions to be run on image once it is complete.

var img = new Image(); 
img.src = imgURL; 
img.id = ''new_image''; 

$(img).load(function() { 
    //once image loaded, add it into div with imageholder id
    $("#imageholder").append(img); 
});

0 responses to “jQuery Image Preload”

leave a reply

Leave this field empty: