Spaces:
Running
Running
Create script.js
Browse files
script.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Function to fetch and display images from the 'spidey' folder
|
| 2 |
+
function loadSpiderManImages() {
|
| 3 |
+
const imageGallery = document.getElementById('image-gallery');
|
| 4 |
+
|
| 5 |
+
// Replace 'spidey/' with the actual path to your 'spidey' folder
|
| 6 |
+
const folderPath = 'spidey/';
|
| 7 |
+
|
| 8 |
+
// Fetch a list of images in the folder
|
| 9 |
+
fetch(folderPath)
|
| 10 |
+
.then(response => response.text())
|
| 11 |
+
.then(data => {
|
| 12 |
+
const imageFilenames = data.split('\n').filter(filename => filename.trim() !== '');
|
| 13 |
+
|
| 14 |
+
// Create image elements and append them to the gallery
|
| 15 |
+
imageFilenames.forEach(filename => {
|
| 16 |
+
const img = document.createElement('img');
|
| 17 |
+
img.src = folderPath + filename;
|
| 18 |
+
img.alt = filename;
|
| 19 |
+
imageGallery.appendChild(img);
|
| 20 |
+
});
|
| 21 |
+
})
|
| 22 |
+
.catch(error => console.error('Error loading images:', error));
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
// Call the function to load Spider-Man images when the page loads
|
| 26 |
+
window.onload = loadSpiderManImages;
|