-
Notifications
You must be signed in to change notification settings - Fork 0
/
lazyload.min.js
1 lines (1 loc) · 1.02 KB
/
lazyload.min.js
1
!function(t,e){var n=function(t){var e=t.image,n=t.src;e.setAttribute("src",n),e.addEventListener("load",function(){e.style.opacity="1"})},i=function(t,e){var n=t.parentNode.insertBefore(e,t);n.appendChild(t)},r=function(t){var n=t.getAttribute("ratio").split("x"),r=parseInt(n[1],10)/parseInt(n[0],10)*100,a=e.createElement("div");a.classList.add("lazy-image"),a.style.paddingBottom=r+"%",i(t,a)},a=function(i){var a=[];return[].forEach.call(e.querySelectorAll(i),function(e){var i=e.getAttribute("data-src");r(e);var o={image:e,src:i},c=e.parentNode.getBoundingClientRect();c.top<t.innerHeight?n(o):a.push(o)}),a},o=function(){var i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"img",r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,o=a(i),c=0;e.addEventListener("scroll",function i(){c===o.length&&e.removeEventListener("scroll",i),o.forEach(function(e,i){if(e){var a=e.image,l=a.parentNode.getBoundingClientRect();l.top<t.innerHeight+r&&l.bottom+l.height+r>0&&(n(e),o[i]=null,c+=1)}})})};t.lazyLoad=o}(window,document);