This commit is contained in:
electronicfreak 2024-03-31 12:55:43 +02:00
parent 0798e94040
commit dd82088551
3 changed files with 23 additions and 0 deletions

8
lazy-img.css Normal file
View File

@ -0,0 +1,8 @@
img[loading='lazy'] {
opacity: 0;
transition: opacity 0.5s ease !important;
}
img.loaded {
opacity: 1;
}

14
lazy-img.js Normal file
View File

@ -0,0 +1,14 @@
document.addEventListener("DOMContentLoaded", function() {
/*var cssLink = document.createElement("link");
cssLink.rel = "stylesheet";
cssLink.href = "/cssjs/lazy-img.css";
document.head.appendChild(cssLink);*/
var images = document.querySelectorAll('img[loading="lazy"]');
images.forEach(function(image) {
image.onload = function() {
image.classList.add('loaded');
};
});
});

1
lazy-img.min.js vendored Normal file
View File

@ -0,0 +1 @@
document.addEventListener("DOMContentLoaded",function(){document.querySelectorAll('img[loading="lazy"]').forEach(function(n){n.onload=function(){n.classList.add("loaded")}})});