@z-utils/vue
Version:
zzy 工具库/vue
2 lines (1 loc) • 1.11 kB
JavaScript
var e=void 0,t=function(t){var n,r=Array.prototype.slice.call(t?document.querySelectorAll(".".concat(t)):document.getElementsByTagName("img"));r=r.filter((function(e){return e.dataset.src}));var o=function(){for(var e=r.length,t=0;t<e;t++){var o=r[t];o.getBoundingClientRect().top<document.documentElement.clientHeight&&(o.src=o.dataset.src,r.splice(t,1),e--,t--,0===r.length&&document.removeEventListener("scroll",n))}},c=function(t){var n,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:100,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:30,c=0,i=e;return function(){var e=+new Date,a=Array.prototype.slice.call(arguments);clearTimeout(n),c||(c=e),e-c>o?(t.apply(i,a),c=e):n=setTimeout((function(){t.apply(i,a)}),r)}};!function(){if("IntersectionObserver"in window){var t=new IntersectionObserver((function(e,n){e.forEach((function(e,n){if(e.isIntersecting){var o=e.target;o.src=o.dataset.src,o.classList.remove("lazy-image"),t.unobserve(o),r.splice(n,1)}}))}));r.forEach((function(e){t.observe(e)}))}else o(),n=c(o),document.addEventListener("scroll",n.bind(e))}()};export{t as default};