Spaces:
Running
Running
Update index.html
Browse files- index.html +63 -29
index.html
CHANGED
|
@@ -7,15 +7,42 @@
|
|
| 7 |
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
<style>
|
| 9 |
.masonry-grid {
|
| 10 |
-
display:
|
|
|
|
| 11 |
gap: 1rem;
|
| 12 |
width: 100%;
|
| 13 |
}
|
| 14 |
|
| 15 |
-
.
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
}
|
| 20 |
|
| 21 |
.toast {
|
|
@@ -94,12 +121,19 @@
|
|
| 94 |
</div>
|
| 95 |
</div>
|
| 96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
<script>
|
| 98 |
// Initialize variables
|
| 99 |
const dropZone = document.getElementById('dropZone');
|
| 100 |
const fileInput = document.getElementById('fileInput');
|
| 101 |
const gallery = document.getElementById('gallery');
|
| 102 |
const noImages = document.getElementById('noImages');
|
|
|
|
|
|
|
| 103 |
let images = [];
|
| 104 |
|
| 105 |
// Toast notification function
|
|
@@ -114,39 +148,34 @@
|
|
| 114 |
}, 3000);
|
| 115 |
}
|
| 116 |
|
| 117 |
-
//
|
| 118 |
-
function
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
gallery.innerHTML = '';
|
| 124 |
|
| 125 |
-
// Create columns
|
| 126 |
-
const columnDivs = Array.from({ length: columns }, () => {
|
| 127 |
-
const div = document.createElement('div');
|
| 128 |
-
div.className = 'masonry-column';
|
| 129 |
-
return div;
|
| 130 |
-
});
|
| 131 |
-
|
| 132 |
-
// Distribute images among columns
|
| 133 |
images.forEach((image, index) => {
|
| 134 |
-
const column = index % columns;
|
| 135 |
const imgContainer = document.createElement('div');
|
| 136 |
-
imgContainer.className = '
|
| 137 |
|
| 138 |
const img = document.createElement('img');
|
| 139 |
img.src = image;
|
| 140 |
img.alt = `Gallery image ${index + 1}`;
|
| 141 |
-
img.className = '
|
| 142 |
img.loading = 'lazy';
|
| 143 |
|
|
|
|
| 144 |
imgContainer.appendChild(img);
|
| 145 |
-
|
| 146 |
});
|
| 147 |
-
|
| 148 |
-
// Add columns to gallery
|
| 149 |
-
columnDivs.forEach(column => gallery.appendChild(column));
|
| 150 |
|
| 151 |
// Toggle no images message
|
| 152 |
noImages.style.display = images.length > 0 ? 'none' : 'block';
|
|
@@ -163,7 +192,7 @@
|
|
| 163 |
|
| 164 |
const newImages = imageFiles.map(file => URL.createObjectURL(file));
|
| 165 |
images = [...images, ...newImages];
|
| 166 |
-
|
| 167 |
showToast(`${imageFiles.length} image${imageFiles.length === 1 ? '' : 's'} uploaded`);
|
| 168 |
}
|
| 169 |
|
|
@@ -201,10 +230,15 @@
|
|
| 201 |
e.target.value = '';
|
| 202 |
});
|
| 203 |
|
| 204 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
|
| 206 |
// Initial setup
|
| 207 |
-
|
| 208 |
</script>
|
| 209 |
</body>
|
| 210 |
</html>
|
|
|
|
| 7 |
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
<style>
|
| 9 |
.masonry-grid {
|
| 10 |
+
display: grid;
|
| 11 |
+
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
|
| 12 |
gap: 1rem;
|
| 13 |
width: 100%;
|
| 14 |
}
|
| 15 |
|
| 16 |
+
.image-container {
|
| 17 |
+
aspect-ratio: 1;
|
| 18 |
+
position: relative;
|
| 19 |
+
overflow: hidden;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
.gallery-image {
|
| 23 |
+
position: absolute;
|
| 24 |
+
inset: 0;
|
| 25 |
+
width: 100%;
|
| 26 |
+
height: 100%;
|
| 27 |
+
object-fit: cover;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.modal {
|
| 31 |
+
display: none;
|
| 32 |
+
position: fixed;
|
| 33 |
+
inset: 0;
|
| 34 |
+
background-color: rgba(0, 0, 0, 0.9);
|
| 35 |
+
z-index: 50;
|
| 36 |
+
padding: 2rem;
|
| 37 |
+
cursor: pointer;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
.modal-content {
|
| 41 |
+
max-height: 90vh;
|
| 42 |
+
max-width: 90vw;
|
| 43 |
+
margin: auto;
|
| 44 |
+
display: block;
|
| 45 |
+
object-fit: contain;
|
| 46 |
}
|
| 47 |
|
| 48 |
.toast {
|
|
|
|
| 121 |
</div>
|
| 122 |
</div>
|
| 123 |
|
| 124 |
+
<!-- Modal for full-size image view -->
|
| 125 |
+
<div id="imageModal" class="modal" onclick="closeModal()">
|
| 126 |
+
<img id="modalImage" class="modal-content" src="" alt="Full size image">
|
| 127 |
+
</div>
|
| 128 |
+
|
| 129 |
<script>
|
| 130 |
// Initialize variables
|
| 131 |
const dropZone = document.getElementById('dropZone');
|
| 132 |
const fileInput = document.getElementById('fileInput');
|
| 133 |
const gallery = document.getElementById('gallery');
|
| 134 |
const noImages = document.getElementById('noImages');
|
| 135 |
+
const modal = document.getElementById('imageModal');
|
| 136 |
+
const modalImg = document.getElementById('modalImage');
|
| 137 |
let images = [];
|
| 138 |
|
| 139 |
// Toast notification function
|
|
|
|
| 148 |
}, 3000);
|
| 149 |
}
|
| 150 |
|
| 151 |
+
// Modal functions
|
| 152 |
+
function openModal(imageSrc) {
|
| 153 |
+
modal.style.display = 'flex';
|
| 154 |
+
modalImg.src = imageSrc;
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
function closeModal() {
|
| 158 |
+
modal.style.display = 'none';
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
// Setup gallery grid
|
| 162 |
+
function setupGalleryGrid() {
|
| 163 |
gallery.innerHTML = '';
|
| 164 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
images.forEach((image, index) => {
|
|
|
|
| 166 |
const imgContainer = document.createElement('div');
|
| 167 |
+
imgContainer.className = 'image-container rounded-lg overflow-hidden bg-gray-100 shadow-sm hover:shadow-md transition-all duration-300 cursor-pointer';
|
| 168 |
|
| 169 |
const img = document.createElement('img');
|
| 170 |
img.src = image;
|
| 171 |
img.alt = `Gallery image ${index + 1}`;
|
| 172 |
+
img.className = 'gallery-image';
|
| 173 |
img.loading = 'lazy';
|
| 174 |
|
| 175 |
+
imgContainer.onclick = () => openModal(image);
|
| 176 |
imgContainer.appendChild(img);
|
| 177 |
+
gallery.appendChild(imgContainer);
|
| 178 |
});
|
|
|
|
|
|
|
|
|
|
| 179 |
|
| 180 |
// Toggle no images message
|
| 181 |
noImages.style.display = images.length > 0 ? 'none' : 'block';
|
|
|
|
| 192 |
|
| 193 |
const newImages = imageFiles.map(file => URL.createObjectURL(file));
|
| 194 |
images = [...images, ...newImages];
|
| 195 |
+
setupGalleryGrid();
|
| 196 |
showToast(`${imageFiles.length} image${imageFiles.length === 1 ? '' : 's'} uploaded`);
|
| 197 |
}
|
| 198 |
|
|
|
|
| 230 |
e.target.value = '';
|
| 231 |
});
|
| 232 |
|
| 233 |
+
// Close modal when pressing escape key
|
| 234 |
+
document.addEventListener('keydown', (e) => {
|
| 235 |
+
if (e.key === 'Escape') {
|
| 236 |
+
closeModal();
|
| 237 |
+
}
|
| 238 |
+
});
|
| 239 |
|
| 240 |
// Initial setup
|
| 241 |
+
setupGalleryGrid();
|
| 242 |
</script>
|
| 243 |
</body>
|
| 244 |
</html>
|