We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
0 parents commit fe3a579Copy full SHA for fe3a579
gistfile1.js
@@ -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