This repository has been archived by the owner on Mar 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.lazyload.min.js
1 lines (1 loc) · 1.71 KB
/
jquery.lazyload.min.js
1
(function(a){a.fn.lazyload=function(c){var d={threshold:0,failurelimit:0,event:"scroll",effect:"show",container:window};if(c){a.extend(d,c)}var b=this;if("scroll"==d.event){a(d.container).bind("scroll",function(g){var e=0;b.each(function(){if(!a.belowthefold(this,d)&&!a.rightoffold(this,d)){a(this).trigger("appear")}else{if(e++>d.failurelimit){return false}}});var f=a.grep(b,function(h){return !h.loaded});b=a(f)})}return this.each(function(){var e=this;a(e).attr("original",a(e).attr("src"));if("scroll"!=d.event||a.belowthefold(e,d)||a.rightoffold(e,d)){if(d.placeholder){a(e).attr("src",d.placeholder)}else{a(e).removeAttr("src")}e.loaded=false}else{e.loaded=true}a(e).one("appear",function(){if(!this.loaded){a("<img />").bind("load",function(){a(e).hide().attr("src",a(e).attr("original"))[d.effect](d.effectspeed);e.loaded=true}).attr("src",a(e).attr("original"))}});if("scroll"!=d.event){a(e).bind(d.event,function(f){if(!e.loaded){a(e).trigger("appear")}})}})};a.belowthefold=function(c,d){if(d.container===undefined||d.container===window){var b=a(window).height()+a(window).scrollTop()}else{var b=a(d.container).offset().top+a(d.container).height()}return b<=a(c).offset().top-d.threshold};a.rightoffold=function(c,d){if(d.container===undefined||d.container===window){var b=a(window).width()+a(window).scrollLeft()}else{var b=a(d.container).offset().left+a(d.container).width()}return b<=a(c).offset().left-d.threshold};a.extend(a.expr[":"],{"below-the-fold":"$.belowthefold(a, {threshold : 0, container: window})","above-the-fold":"!$.belowthefold(a, {threshold : 0, container: window})","right-of-fold":"$.rightoffold(a, {threshold : 0, container: window})","left-of-fold":"!$.rightoffold(a, {threshold : 0, container: window})"})})(jQuery);