changed js for gallery
This commit is contained in:
1 parent
f6f880fb65
commit
aa204a2329
1 file changed
+9
-6
+9
-6
@@ -1,12 +1,15 @@
|
|||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
const galleryContainer = document.getElementById('gallery-container');
|
const galleryContainer = document.getElementById('gallery-container');
|
||||||
const totalImages = 50; // number of images you want to load
|
|
||||||
|
|
||||||
for (let i = 1; i <= totalImages; i++) {
|
// Get file list from HTML attribute
|
||||||
|
const files = galleryContainer.dataset.files.split(',');
|
||||||
|
|
||||||
|
files.forEach((file, index) => {
|
||||||
const img = document.createElement('img');
|
const img = document.createElement('img');
|
||||||
img.src = `gallery/${i}.jpg`; // assuming .jpg extension, change if needed
|
img.src = `gallery/${file.trim()}`;
|
||||||
img.alt = `Image ${i}`;
|
img.alt = `Image ${index + 1}`;
|
||||||
img.onerror = () => { img.style.display = 'none'; }; // hide broken images
|
img.onerror = () => { img.style.display = 'none'; }; // hide broken
|
||||||
galleryContainer.appendChild(img);
|
galleryContainer.appendChild(img);
|
||||||
}
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
Reference in new issue
Block a user