0

ToolBox – Preloading With Jquery

Posted November 12th, 2009 in Featured, JQuery, Toolbox and tagged , , , , , , , , by Jon

I thought I’d start a new Category called “Toolbox”, specifically for what I use on a daily basis for web development. These are snippets, functions, cheats, etc that anyone can use and make my life as a web developer that much easier…

This installment is something I’ve been using lately to preload images so they don’t spit out the alt text…Mostly it seems to happen when I’m doing something with ajax.

I found this snippet at Matt Farina’s blog.

This is the code (I just made a js file out of it and include it when necessary).

jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length;i++) {
      jQuery("<img>").attr("src", arguments[i]);
  }
}

It’s easy to call and use.

$(document).ready(function() {
    $.preloadImages("/images/small-loader.gif");
});

See wasn’t that easy? So if you keep a toolbox of development goodies, add this one – if you aren’t you probably ought to start one.

Leave a Reply





CommentLuv badge