forked from tuupola/lazyload
-
Notifications
You must be signed in to change notification settings - Fork 1
/
jquery.lazyload.min.js
1 lines (1 loc) · 1.43 KB
/
jquery.lazyload.min.js
1
(function(b,a){b.fn.lazyload=function(p){var d=function(r){var q=b(r).offset();if(/; CPU.*OS (?:3_2|4_0)/i.test(navigator.userAgent)&&"getBoundingClientRect" in document.documentElement){q.top-=a.scrollY;q.left-=a.scrollX}return q};var j=!1,l="original",k="src",i=!j,c=this,h={threshold:0,container:a,effect:"show",namespace:".lazyload"};if(p){b.extend(h,p)}var e=b(h.container),g=h.namespace,n="appear"+g,f="resize"+g,m="scroll"+g;var o=function(v){v=b(v);if(!v.length){return false}var w=h.threshold,u;if(e[0]===a){var q=e.height()+e.scrollTop(),t=e.scrollLeft(),A=e.width()+e.scrollLeft(),y=e.scrollTop()}else{u=d(e);var q=u.top+e.height(),t=u.left,A=u.left+e.width(),y=u.top}u=d(v);var z=u.top+v.height(),r=u.left,x=u.left+v.width(),s=u.top;return(s+w)<=q&&(r+w)<=A&&(z-w)>=y&&(x-w)>t};c.each(function(){var q=this;if(o(b(q))){q.loaded=i;if(b(q).attr(l)){b(q).attr(k,b(q).attr(l))}return}b(q).data(l,b(q).attr(l)||b(q).attr(k));if(!b(q).attr(k)||h.placeholder===b(q).attr(k)||(!o(b(q)))){h.placeholder?b(q).attr(k,h.placeholder):b(q).removeAttr(k);q.loaded=j}b(q).one(n,function(){if(this.loaded){return}b("<img />").load(function(){b(q).hide().attr(k,b(q).data(l))[h.effect](h.effectSpeed).removeData(l);q.loaded=i}).attr(k,b(q).data(l))})});e.bind(m+" "+f,function(){var q=0;c.each(function(){var r=this;if(o(r)&&!r.loaded){b(r).trigger(n)}});c=b(b.grep(c,function(r){return !r.loaded}));if(!c.length){e.unbind(g)}}).trigger(m);return this}})(jQuery,window);