night-peiqi
Version:
## Install
2 lines (1 loc) • 1.3 kB
JavaScript
import{jsx as e}from"react/jsx-runtime";import{useMemo as t,useEffect as n}from"react";var a="index-module_lazyImage__7N6hM";!function(e,t){void 0===t&&(t={});var n=t.insertAt;if(e&&"undefined"!=typeof document){var a=document.head||document.getElementsByTagName("head")[0],r=document.createElement("style");r.type="text/css","top"===n&&a.firstChild?a.insertBefore(r,a.firstChild):a.appendChild(r),r.styleSheet?r.styleSheet.cssText=e:r.appendChild(document.createTextNode(e))}}(".index-module_lazyImage__7N6hM {\n width: 100%;\n min-height: 10px;\n}\n");var r=function(r){var c=t((function(){return(new Image).loading}),[]);return n((function(){if(!c){var e=document.querySelectorAll("img[data-src]");if(!window||!window.IntersectionObserver)return;var t=new IntersectionObserver((function(e){e.forEach((function(e){e.isIntersecting&&(!function(e){e.setAttribute("src",e.getAttribute("data-src")||""),e.addEventListener("load",(function(){e.removeAttribute("data-src")}))}(e.target),t.unobserve(e.target))}))}));e.forEach((function(e){t.observe(e)}))}}),[]),e("img",c?{className:"".concat(a," ").concat(r.className||""),src:r.src,alt:"lazy",loading:"lazy"}:{alt:"lazy",className:"".concat(a," ").concat(r.className||""),src:r.defaultimg,"data-src":r.src,loading:"lazy"})};export{r as LazyImage};