Files
DefectingCat.github.io/js/lazyload.js
DefectingCat 8c7085f18f
2020-11-02 02:17:54 +00:00

1 line
966 B
JavaScript

!function(e,t){var n=void 0!==e&&"IntersectionObserver"in e,r=Array.prototype.slice.call(t.querySelectorAll("img[srcset]"));if(r&&0!==r.length)if(n){var o=new IntersectionObserver((function(e){e.forEach(({target:e,isIntersecting:t})=>{t&&(e.setAttribute("srcset",e.src),e.onload=e.onerror=()=>o.unobserve(e))})}),{threshold:[0],rootMargin:(e.innerHeight||t.documentElement.clientHeight)+"px"});r.map(e=>o.observe(e))}else{function i(e,t){var n=new Image,r=e.getAttribute("src");n.onload=function(){e.srcset=r,t&&t()},n.srcset=r}var c=new Debouncer((function(){for(var n=0;n<r.length;n++)o=r[n],s=void 0,l=void 0,v=void 0,s=o.getBoundingClientRect(),l=e.innerHeight||t.documentElement.clientHeight,((v=s.top)>=0&&v<=3*l||v<=0&&v<=-2*l-s.height)&&function(e){var t=r[e];i(t,(function(){r=r.filter((function(e){return t!==e}))}))}(n);var o,s,l,v;0===r.length&&e.removeEventListener("scroll",c,!1)}));e.addEventListener("scroll",c,!1),c.handleEvent()}}(window,document);