diff --git a/temp/temp.js b/temp/temp.js
index e61bac6..3fff579 100644
--- a/temp/temp.js
+++ b/temp/temp.js
@@ -168,31 +168,41 @@ ${imageUrls.map(url => `
![]()
= 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();
})();