Update temp/temp.js

This commit is contained in:
aka paul 2025-10-26 22:57:23 +00:00
parent 985708a59a
commit 529b900ba7

View file

@ -168,31 +168,41 @@ ${imageUrls.map(url => ` <div class="img-container"><img data-src="${url}" al
(function() { (function() {
var images = document.querySelectorAll('img[data-src]'); var images = document.querySelectorAll('img[data-src]');
var containers = document.querySelectorAll('.img-container'); var containers = document.querySelectorAll('.img-container');
var loadQueue = []; var currentIndex = 0;
var loading = false;
function loadImage(index) { function loadNext() {
if (index >= images.length || loading) return; if (currentIndex >= images.length) return;
loading = true;
var img = images[index]; var img = images[currentIndex];
var container = containers[index]; var container = containers[currentIndex];
img.src = img.dataset.src; var index = currentIndex;
// Set up handlers BEFORE setting src
img.onload = function() { img.onload = function() {
container.style.minHeight = img.naturalHeight + 'px'; container.style.minHeight = this.naturalHeight + 'px';
img.classList.add('loaded'); this.classList.add('loaded');
loading = false; currentIndex++;
loadImage(index + 1); setTimeout(loadNext, 100);
}; };
img.onerror = function() { img.onerror = function() {
loading = false; currentIndex++;
loadImage(index + 1); setTimeout(loadNext, 100);
}; };
// Check if already loaded (cached)
if (img.complete && img.naturalHeight > 0) {
container.style.minHeight = img.naturalHeight + 'px';
img.classList.add('loaded');
currentIndex++;
setTimeout(loadNext, 100);
} else {
// Set src to trigger load
img.src = img.dataset.src;
}
} }
loadImage(0); loadNext();
})(); })();
</script> </script>
</body> </body>