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() {
|
||||
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>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue