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() {
var images = document.querySelectorAll('img[data-src]');
var containers = document.querySelectorAll('.img-container');
var loadQueue = [];
var loading = false;
var currentIndex = 0;
function loadImage(index) {
if (index >= images.length || loading) return;
loading = true;
function loadNext() {
if (currentIndex >= images.length) return;
var img = images[index];
var container = containers[index];
img.src = img.dataset.src;
var img = images[currentIndex];
var container = containers[currentIndex];
var index = currentIndex;
// Set up handlers BEFORE setting src
img.onload = function() {
container.style.minHeight = img.naturalHeight + 'px';
img.classList.add('loaded');
loading = false;
loadImage(index + 1);
container.style.minHeight = this.naturalHeight + 'px';
this.classList.add('loaded');
currentIndex++;
setTimeout(loadNext, 100);
};
img.onerror = function() {
loading = false;
loadImage(index + 1);
currentIndex++;
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>
</body>