jQuery preloading images


/ Published in: JavaScript
Save to your folder(s)

Thanks to Matt Farina

Also see similar snippet for preloading arbitrary content, e.g. media in content received via AJAX.


Copy this code and paste it in your HTML
  1. // preloading function of images
  2. jQuery.preloadImages = function()
  3. {
  4. for(var i = 0; i<arguments.length; i++)
  5. {
  6. jQuery("<img>").attr("src", arguments[i]);
  7. }
  8. };
  9.  
  10. // use like
  11. $.preloadImages("image1.gif", "/path/to/image2.png", "some/image3.jpg");

URL: http://www.innovatingtomorrow.net/2008/04/30/preloading-content-jquery

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.