lazy-loading done
This commit is contained in:
@@ -204,5 +204,30 @@ const canonicalUrl = `${siteUrl}${canonicalPath.startsWith("/") ? canonicalPath
|
||||
mql.addEventListener("change", () => setOpen(!mql.matches));
|
||||
})();
|
||||
</script>
|
||||
|
||||
<script is:inline>
|
||||
(() => {
|
||||
function reveal(img) {
|
||||
img.classList.remove("img-loading");
|
||||
img.classList.add("img-loaded");
|
||||
var wrap = img.closest(".img-shimmer-wrap");
|
||||
if (wrap) wrap.classList.add("img-loaded");
|
||||
}
|
||||
var imgs = document.querySelectorAll("img.img-loading");
|
||||
for (var i = 0; i < imgs.length; i++) {
|
||||
(function(img) {
|
||||
if (img.complete && img.naturalWidth > 0) {
|
||||
reveal(img);
|
||||
return;
|
||||
}
|
||||
img.addEventListener("load", function() { reveal(img); });
|
||||
img.addEventListener("error", function() {
|
||||
var wrap = img.closest(".img-shimmer-wrap");
|
||||
if (wrap) wrap.classList.add("img-error");
|
||||
});
|
||||
})(imgs[i]);
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user