imgLoading.js 728 B

1
  1. (()=>{function t(){var t=document.documentElement.clientHeight,e=(document.documentElement.scrollTop||document.body.scrollTop,document.querySelectorAll("img[data-src]"));Array.prototype.forEach.call(e,function(e,o){var c;""!==e.getAttribute("data-src")&&(c=e.getBoundingClientRect()).bottom>=0&&c.top<t&&function(){var t=new Image;t.src=e.getAttribute("data-src"),e.src=t.src;var o=0;setInterval(function(){(o+=.2)<=1&&(e.style.opacity=o)},100),e.removeAttribute("data-src")}()})}window.onload=function(){for(var e=document.querySelectorAll("img[data-src]"),o=0;o<e.length;o++)e[o].style.opacity="0";t()},window.onscroll=function(){0!==document.querySelectorAll("img[data-src]").length&&(t(),this.console.log("加载..."))}})();