fix: lazy load portraits
This commit is contained in:
parent
06bcdae2d1
commit
43c862fbfd
@ -25,8 +25,3 @@ img.lazy-image {
|
|||||||
opacity: 0;
|
opacity: 0;
|
||||||
transition: opacity 0.3s ease;
|
transition: opacity 0.3s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
img.lazy-image.loaded {
|
|
||||||
opacity: 1;
|
|
||||||
z-index:-1;
|
|
||||||
}
|
|
||||||
|
@ -1,16 +1,17 @@
|
|||||||
window.onload = function(){
|
window.onload = function () {
|
||||||
|
// Get all <img> elements with loading="lazy"
|
||||||
|
var lazyImages = document.querySelectorAll('img[loading="lazy"]');
|
||||||
|
|
||||||
var lazyImages = [...document.querySelectorAll("img[loading='lazy']")];
|
// Loop through each image and apply the fade-in effect
|
||||||
|
lazyImages.forEach(function (lazyImage) {
|
||||||
|
lazyImage.style.opacity = 0;
|
||||||
|
lazyImage.classList.add("lazy-image")
|
||||||
|
|
||||||
for (let i = 0; i < lazyImages.length; i++) {
|
// Create an image element to check when it's loaded
|
||||||
var element = lazyImages[i];
|
var img = new Image();
|
||||||
element.classList.add("lazy-image")
|
img.src = lazyImage.src;
|
||||||
element.onload = function(){
|
img.onload = function () {
|
||||||
element.classList.add("loaded");
|
lazyImage.style.opacity = 1;
|
||||||
}
|
};
|
||||||
element.addEventListener("load", function(){
|
});
|
||||||
element.classList.add("loaded");
|
};
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user