test3
This commit is contained in:
1 parent
291dd705fc
commit
12d114be9f
1 file changed
+17
-2
+17
-2
@@ -4,9 +4,24 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
|
|
||||||
for (let i = 1; i <= totalImages; i++) {
|
for (let i = 1; i <= totalImages; i++) {
|
||||||
const img = document.createElement('img');
|
const img = document.createElement('img');
|
||||||
img.src = `gallery/${i}.jpg`; // assuming .jpg extension, change if needed
|
|
||||||
img.alt = `Image ${i}`;
|
img.alt = `Image ${i}`;
|
||||||
img.onerror = () => { img.style.display = 'none'; }; // hide broken images
|
|
||||||
|
// Try jpg first
|
||||||
|
img.src = `gallery/${i}.jpg`;
|
||||||
|
|
||||||
|
// fallback to png
|
||||||
|
img.onerror = () => {
|
||||||
|
img.src = `gallery/${i}.png`;
|
||||||
|
|
||||||
|
// fallback to gif
|
||||||
|
img.onerror = () => {
|
||||||
|
img.src = `gallery/${i}.gif`;
|
||||||
|
|
||||||
|
// hide if all fail
|
||||||
|
img.onerror = () => { img.style.display = 'none'; };
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
galleryContainer.appendChild(img);
|
galleryContainer.appendChild(img);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user