mirror of
https://git.luna-app.eu/50n50/sources
synced 2025-12-21 21:26:19 +01:00
Update temp/temp.js
This commit is contained in:
parent
985708a59a
commit
529b900ba7
1 changed files with 25 additions and 15 deletions
40
temp/temp.js
40
temp/temp.js
|
|
@ -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>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue