!function(t,i){"function"==typeof define&&define.amd?define([],i):"object"==typeof exports?module.exports=i():t.Layzr=i()}(this,function(){"use strict";function t(t){this._lastScroll=0,this._ticking=!1,this._optionsAttr=t.attr||"data-layzr",this._optionsAttrRetina=t.retinaAttr||"data-layzr-retina",this._optionsThreshold=t.threshold||0,this._optionsCallback=t.callback||null,this._retina=window.devicePixelRatio>1?!0:!1,this._imgAttr=this._retina?this._optionsAttrRetina:this._optionsAttr,this._images=document.getElementsByTagName("img"),document.addEventListener("DOMContentLoaded",this._create(),!1)}return t.prototype._requestScroll=function(){this._lastScroll=window.scrollY||window.pageYOffset,this._requestTick()},t.prototype._requestTick=function(){this._ticking||(requestAnimationFrame(this.update.bind(this)),this._ticking=!1)},t.prototype._create=function(){this._requestScroll(),window.addEventListener("scroll",this._requestScroll.bind(this),!1),window.addEventListener("resize",this._requestScroll.bind(this),!1)},t.prototype._destroy=function(){window.removeEventListener("scroll",this._requestScroll.bind(this),!1),window.removeEventListener("resize",this._requestScroll.bind(this),!1)},t.prototype._getOffset=function(t){var i=0;do isNaN(t.offsetTop)||(i+=t.offsetTop);while(t=t.offsetParent);return i},t.prototype._inViewport=function(t){var i=this._lastScroll,e=i+window.innerHeight,o=this._getOffset(t),s=o+t.offsetHeight,r=this._optionsThreshold/100*window.innerHeight;return s>=i-r&&e+r>=s},t.prototype.update=function(){for(var t=this._images.length,i=0;t>i;i++){var e=this._images[i];(e.hasAttribute(this._imgAttr)||e.hasAttribute(this._optionsAttr))&&this._inViewport(e)&&this.reveal(e)}this._ticking=!1},t.prototype.reveal=function(t){var i=t.getAttribute(this._imgAttr)||t.getAttribute(this._optionsAttr);t.removeAttribute(this._optionsAttr),t.removeAttribute(this._optionsAttrRetina),i&&(t.setAttribute("src",i),"function"==typeof this._optionsCallback&&this._optionsCallback.call(t))},t});
!function(t,i){"function"==typeof define&&define.amd?define([],i):"object"==typeof exports?module.exports=i():t.Layzr=i()}(this,function(){"use strict";function t(t){this._lastScroll=0,this._ticking=!1,this._optionsAttr=t.attr||"data-layzr",this._optionsAttrRetina=t.retinaAttr||"data-layzr-retina",this._optionsThreshold=t.threshold||0,this._optionsCallback=t.callback||null,this._retina=window.devicePixelRatio>1?!0:!1,this._imgAttr=this._retina?this._optionsAttrRetina:this._optionsAttr,this._images=document.getElementsByTagName("img"),document.addEventListener("DOMContentLoaded",this._create(),!1)}return t.prototype._requestScroll=function(){this._lastScroll=window.scrollY||window.pageYOffset,this._requestTick()},t.prototype._requestTick=function(){this._ticking||(requestAnimationFrame(this.update.bind(this)),this._ticking=!0)},t.prototype._create=function(){this._requestScroll(),window.addEventListener("scroll",this._requestScroll.bind(this),!1),window.addEventListener("resize",this._requestScroll.bind(this),!1)},t.prototype._destroy=function(){window.removeEventListener("scroll",this._requestScroll.bind(this),!1),window.removeEventListener("resize",this._requestScroll.bind(this),!1)},t.prototype._getOffset=function(t){var i=0;do isNaN(t.offsetTop)||(i+=t.offsetTop);while(t=t.offsetParent);return i},t.prototype._inViewport=function(t){var i=this._lastScroll,e=i+window.innerHeight,o=this._getOffset(t),s=o+t.offsetHeight,r=this._optionsThreshold/100*window.innerHeight;return s>=i-r&&e+r>=s},t.prototype.update=function(){for(var t=this._images.length,i=0;t>i;i++){var e=this._images[i];(e.hasAttribute(this._imgAttr)||e.hasAttribute(this._optionsAttr))&&this._inViewport(e)&&this.reveal(e)}this._ticking=!1},t.prototype.reveal=function(t){var i=t.getAttribute(this._imgAttr)||t.getAttribute(this._optionsAttr);t.removeAttribute(this._optionsAttr),t.removeAttribute(this._optionsAttrRetina),i&&(t.setAttribute("src",i),"function"==typeof this._optionsCallback&&this._optionsCallback.call(t))},t});
update minified version to include debouncing fix as well