Posted By

dougunderscorenelson on 06/25/09


image jquery

Versions (?)

Who likes this?

4 people have marked this snippet as a favorite


Has the image loaded?

 / Published in: jQuery

Used this on a project to determine whether images were loaded or not. In an image carousel, for example, you could test the next/clicked image before advancing the slide, and if 'loaded' wasn't 'true', you could add a "loading" class and attach a new .load handler to remove the class and advance when the image finished loading.

  1. $("img").each(function(){
  2. i = $(this).attr('src');
  3. $(this).attr('src','')
  4. $(this).load(function(){
  5. $(this).data('loaded','true');
  6. });
  7. $(this).attr('src',i);
  8. });

Report this snippet  

You need to login to post a comment.