Posted By

ionutzp on 11/05/10


Tagged

javascript jquery


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

ionutzp
wirenaught


Images Loaded Jquery plugin


 / Published in: JavaScript
 

seen at Eric Miraglia

  1. $.fn.imagesLoaded = function(callback){
  2. var elems = this.filter('img'),
  3. len = elems.length;
  4.  
  5. elems.bind('load',function(){
  6. if (--len <= 0){
  7. //console.log(elems, this);
  8. callback.call(elems,this); }
  9. }).each(function(){
  10. // cached images don't fire load sometimes, so we reset src.
  11. if (this.complete || this.complete === undefined){
  12. var src = this.src;
  13. // webkit hack from http://groups.google.com/group/jquery-dev/browse_thread/thread/eee6ab7b2da50e1f
  14. // data uri bypasses webkit log warning (thx doug jones)
  15. this.src = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";
  16. this.src = src;
  17. }
  18. });
  19.  
  20. return this;
  21. };

Report this snippet  

You need to login to post a comment.