Preload images using jQuery


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



Copy this code and paste it in your HTML
  1. <script type="text/javascript" charset="utf-8">
  2. // JQUERY WAY TO PRELOAD IMAGES
  3. // DOES NOT NEED TO BE IN DOCUMENT READY
  4. $.preloadImages = function()
  5. {
  6. for(var i = 0; i<arguments.length; i++)
  7. {
  8. img = new Image();
  9. img.src = arguments[i];
  10. }
  11.  
  12. }
  13. $.preloadImages(
  14. "path/to/image/1",
  15. "path/to/image/2",
  16. "path/to/image/3"
  17. );
  18. </script>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.