Loading images before it is been used using Javascript.

Posted by Prabhukiran345 under JavaScript category on | Points: 40 | Views : 980
Hi all,
When we were using images in Javascript,it is a good thing to preload it before we use it.
This can be achieved by using following code
jQuery.preloadImages = function()


for(var i = 0; i”).attr(“src”, arguments[i]);



// Usage

$.preloadImages(“image1.gif”, “/path/to/image2.png”, “some/image3.jpg”);

Note:To show the scenario i have hotcoded static paths of image.

Comments or Responses

Login to post response