Images Loaded Jquery plugin


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

seen at Eric Miraglia


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.