forked from tuupola/lazyload
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.lazyload.min.js
16 lines (16 loc) · 3.26 KB
/
jquery.lazyload.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*
* Lazy Load - jQuery plugin for lazy loading images
*
* Copyright (c) 2007-2012 Mika Tuupola
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/mit-license.php
*
* Project home:
* http://www.appelsiini.net/projects/lazyload
*
* Version: 1.8.0
* 1.8.1-forked-2012-09-24-jonmcl
*
*/
(function(e,t){var n=e(t),r=[];e.fn.lazyload=function(i){function a(){var t=0;s.each(function(){var n=e(this);if(u.skip_invisible&&!n.is(":visible"))return;if(!e.abovethetop(this,u)&&!e.leftofbegin(this,u))if(!e.belowthefold(this,u)&&!e.rightoffold(this,u))n.trigger("appear");else if(++t>u.failure_limit)return!1})}var s=this,o,u={threshold:0,failure_limit:0,event:"scroll",effect:"show",container:t,data_attribute:"original",skip_invisible:!0,appear:null,load:null,only_once:!1};return i&&(undefined!==i.failurelimit&&(i.failure_limit=i.failurelimit,delete i.failurelimit),undefined!==i.effectspeed&&(i.effect_speed=i.effectspeed,delete i.effectspeed),e.extend(u,i)),o=u.container===undefined||u.container===t?n:e(u.container),0===u.event.indexOf("scroll")&&o.bind(u.event,function(e){return a()}),this.each(function(){var t=this,n=e(t);if(u.only_once){var i=n.data(u.data_attribute);if(e.inArray(i,r)>=0){n.attr("src",n.data(u.data_attribute)),n.loaded=!0;return}}t.loaded=!1,n.one("appear",function(){if(!this.loaded){if(u.appear){var i=s.length;u.appear.call(t,i,u)}e("<img />").bind("load",function(){n.hide().attr("src",n.data(u.data_attribute))[u.effect](u.effect_speed),t.loaded=!0;var i=e.grep(s,function(e){return!e.loaded});s=e(i),u.only_once&&e.inArray(n.data(u.data_attribute),r)==-1&&r.push(n.data(u.data_attribute));if(u.load){var o=s.length;u.load.call(t,o,u)}}).attr("src",n.data(u.data_attribute))}}),0!==u.event.indexOf("scroll")&&n.bind(u.event,function(e){t.loaded||n.trigger("appear")})}),n.bind("resize",function(e){a()}),this},e.belowthefold=function(r,i){var s;return i.container===undefined||i.container===t?s=n.height()+n.scrollTop():s=e(i.container).offset().top+e(i.container).height(),s<=e(r).offset().top-i.threshold},e.rightoffold=function(r,i){var s;return i.container===undefined||i.container===t?s=n.width()+n.scrollLeft():s=e(i.container).offset().left+e(i.container).width(),s<=e(r).offset().left-i.threshold},e.abovethetop=function(r,i){var s;return i.container===undefined||i.container===t?s=n.scrollTop():s=e(i.container).offset().top,s>=e(r).offset().top+i.threshold+e(r).height()},e.leftofbegin=function(r,i){var s;return i.container===undefined||i.container===t?s=n.scrollLeft():s=e(i.container).offset().left,s>=e(r).offset().left+i.threshold+e(r).width()},e.inviewport=function(t,n){return!e.rightofscreen(t,n)&&!e.leftofscreen(t,n)&&!e.belowthefold(t,n)&&!e.abovethetop(t,n)},e.extend(e.expr[":"],{"below-the-fold":function(t){return e.belowthefold(t,{threshold:0})},"above-the-top":function(t){return!e.belowthefold(t,{threshold:0})},"right-of-screen":function(t){return e.rightoffold(t,{threshold:0})},"left-of-screen":function(t){return!e.rightoffold(t,{threshold:0})},"in-viewport":function(t){return!e.inviewport(t,{threshold:0})},"above-the-fold":function(t){return!e.belowthefold(t,{threshold:0})},"right-of-fold":function(t){return e.rightoffold(t,{threshold:0})},"left-of-fold":function(t){return!e.rightoffold(t,{threshold:0})}})})(jQuery,window)