Skip to content

Commit fe3a579

Browse files
committed
0 parents  commit fe3a579

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

gistfile1.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// $('img.photo',this).imagesLoaded(myFunction)
2+
// execute a callback when all images have loaded.
3+
// needed because .load() doesn't work on cached images
4+
5+
// mit license. paul irish. 2010.
6+
7+
// callback function is passed the last image to load
8+
// as an argument, and the collection as `this`
9+
10+
$.fn.imagesLoaded = function(callback){
11+
var elems = this.filter('img'),
12+
len = elems.length;
13+
14+
elems.bind('load',function(){
15+
if (--len <= 0){ callback.call(elems,this); }
16+
}).each(function(){
17+
// cached images don't fire load sometimes, so we reset src.
18+
if (this.complete || this.complete === undefined){ this.src = this.src; }
19+
});
20+
}
21+

0 commit comments

Comments
 (0)