<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Modern Image Gallery with Lightbox</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
body {
background: linear-gradient(135deg, #1a2a6c, #b21f1f, #fdbb2d);
min-height: 100vh;
padding: 40px 20px;
display: flex;
justify-content: center;
align-items: center;
}
.container {
width: 100%;
max-width: 1200px;
background: rgba(255, 255, 255, 0.95);
border-radius: 20px;
box-shadow: 0 15px 50px rgba(0, 0, 0, 0.3);
overflow: hidden;
}
header {
background: linear-gradient(to right, #4b6cb7, #182848);
color: white;
padding: 30px;
text-align: center;
}
h1 {
font-size: 2.8rem;
margin-bottom: 10px;
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}
.subtitle {
font-size: 1.2rem;
opacity: 0.9;
max-width: 700px;
margin: 0 auto;
line-height: 1.6;
}
.input-section {
padding: 30px;
background: #f8f9fa;
border-bottom: 1px solid #eaeaea;
}
.input-group {
display: flex;
max-width: 800px;
margin: 0 auto;
box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
border-radius: 12px;
overflow: hidden;
}
#imageUrl {
flex: 1;
padding: 18px 25px;
border: none;
font-size: 1.1rem;
outline: none;
background: white;
}
#generateBtn {
background: linear-gradient(to right, #3498db, #2980b9);
color: white;
border: none;
padding: 0 35px;
font-size: 1.1rem;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
}
#generateBtn:hover {
background: linear-gradient(to right, #2980b9, #2573a7);
transform: translateY(-2px);
}
.example {
text-align: center;
margin-top: 20px;
color: #6c757d;
font-size: 0.95rem;
}
.gallery-container {
padding: 30px;
}
.gallery-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 25px;
}
.gallery-title {
font-size: 1.8rem;
color: #2c3e50;
}
.image-count {
background: #e74c3c;
color: white;
padding: 8px 15px;
border-radius: 20px;
font-weight: bold;
}
.gallery {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
gap: 25px;
}
.gallery-item {
border-radius: 15px;
overflow: hidden;
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
background: white;
height: 300px;
display: flex;
flex-direction: column;
cursor: pointer;
}
.gallery-item:hover {
transform: translateY(-10px);
box-shadow: 0 15px 30px rgba(0, 0, 0, 0.2);
}
.image-container {
flex: 1;
overflow: hidden;
background: #f8f9fa;
display: flex;
align-items: center;
justify-content: center;
}
.gallery-item img {
width: 100%;
height: 100%;
object-fit: cover;
transition: transform 0.5s ease;
}
.gallery-item:hover img {
transform: scale(1.05);
}
.image-info {
padding: 15px;
background: white;
}
.image-filename {
font-weight: 600;
color: #2c3e50;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
margin-bottom: 5px;
}
.image-url {
font-size: 0.85rem;
color: #7f8c8d;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.loading {
display: none;
text-align: center;
padding: 30px;
}
.spinner {
border: 5px solid rgba(0, 0, 0, 0.1);
border-top: 5px solid #3498db;
border-radius: 50%;
width: 50px;
height: 50px;
animation: spin 1s linear infinite;
margin: 0 auto 20px;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.error {
text-align: center;
color: #e74c3c;
padding: 20px;
background: #ffebee;
border-radius: 10px;
margin: 20px auto;
max-width: 600px;
display: none;
}
.placeholder {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100%;
color: #95a5a6;
}
.placeholder i {
font-size: 3rem;
margin-bottom: 15px;
}
footer {
text-align: center;
padding: 25px;
color: #7f8c8d;
font-size: 0.9rem;
background: #f8f9fa;
border-top: 1px solid #eaeaea;
}
/* Lightbox Styles */
.lightbox {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.9);
z-index: 1000;
justify-content: center;
align-items: center;
}
.lightbox-content {
position: relative;
max-width: 90%;
max-height: 90%;
text-align: center;
}
.lightbox-img {
max-width: 100%;
max-height: 80vh;
border-radius: 10px;
box-shadow: 0 5px 25px rgba(0, 0, 0, 0.5);
}
.lightbox-info {
color: white;
margin-top: 15px;
font-size: 1.2rem;
}
.lightbox-controls {
position: absolute;
top: 20px;
right: 20px;
display: flex;
gap: 15px;
}
.lightbox-btn {
background: rgba(255, 255, 255, 0.2);
color: white;
border: none;
width: 50px;
height: 50px;
border-radius: 50%;
font-size: 1.5rem;
cursor: pointer;
transition: all 0.3s ease;
display: flex;
justify-content: center;
align-items: center;
}
.lightbox-btn:hover {
background: rgba(255, 255, 255, 0.3);
transform: scale(1.1);
}
.lightbox-nav {
position: absolute;
top: 50%;
transform: translateY(-50%);
width: 100%;
display: flex;
justify-content: space-between;
padding: 0 20px;
}
.nav-btn {
background: rgba(255, 255, 255, 0.2);
color: white;
border: none;
width: 60px;
height: 60px;
border-radius: 50%;
font-size: 1.8rem;
cursor: pointer;
transition: all 0.3s ease;
display: flex;
justify-content: center;
align-items: center;
}
.nav-btn:hover {
background: rgba(255, 255, 255, 0.3);
}
@media (max-width: 768px) {
.gallery {
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}
.input-group {
flex-direction: column;
}
#generateBtn {
padding: 15px;
}
h1 {
font-size: 2.2rem;
}
.lightbox-controls {
top: 10px;
right: 10px;
}
.lightbox-btn {
width: 40px;
height: 40px;
font-size: 1.2rem;
}
.nav-btn {
width: 50px;
height: 50px;
font-size: 1.5rem;
}
}
</style>
</head>
<body>
<div class="container">
<header>
<h1><i class="fas fa-images"></i> Modern Image Gallery</h1>
<p class="subtitle">Enter an image URL pattern and we'll generate a gallery of images by incrementing the filename from 01 to 16</p>
</header>
<div class="input-section">
<div class="input-group">
<input type="text" id="imageUrl" placeholder="Enter image URL (e.g., https://example.com/images/06.jpg)">
<button id="generateBtn">Generate Gallery</button>
</div>
<p class="example">Example: https://example.com/images/06.jpg → Generates images from 01.jpg to 16.jpg</p>
</div>
<div class="error" id="errorMessage"></div>
<div class="loading" id="loadingIndicator">
<div class="spinner"></div>
<p>Loading images, please wait...</p>
</div>
<div class="gallery-container">
<div class="gallery-header">
<h2 class="gallery-title">Image Gallery</h2>
<div class="image-count">16 Images</div>
</div>
<div class="gallery" id="imageGallery">
<!-- Gallery items will be inserted here -->
<div class="gallery-item placeholder-item">
<div class="image-container">
<div class="placeholder">
<i class="fas fa-cloud-arrow-up"></i>
<p>Enter URL to generate gallery</p>
</div>
</div>
</div>
</div>
</div>
<footer>
<p>Modern Image Gallery Generator © 2023 | Click on any image to view in lightbox</p>
</footer>
</div>
<!-- Lightbox Popup -->
<div class="lightbox" id="lightbox">
<div class="lightbox-nav">
<button class="nav-btn" id="prevBtn"><i class="fas fa-chevron-left"></i></button>
<button class="nav-btn" id="nextBtn"><i class="fas fa-chevron-right"></i></button>
</div>
<div class="lightbox-content">
<div class="lightbox-controls">
<button class="lightbox-btn" id="fullscreenBtn" title="Open in new tab">
<i class="fas fa-external-link-alt"></i>
</button>
<button class="lightbox-btn" id="closeBtn" title="Close">
<i class="fas fa-times"></i>
</button>
</div>
<img class="lightbox-img" id="lightboxImg" src="" alt="Enlarged view">
<div class="lightbox-info" id="lightboxInfo"></div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const imageUrlInput = document.getElementById('imageUrl');
const generateBtn = document.getElementById('generateBtn');
const imageGallery = document.getElementById('imageGallery');
const loadingIndicator = document.getElementById('loadingIndicator');
const errorMessage = document.getElementById('errorMessage');
const lightbox = document.getElementById('lightbox');
const lightboxImg = document.getElementById('lightboxImg');
const lightboxInfo = document.getElementById('lightboxInfo');
const closeBtn = document.getElementById('closeBtn');
const fullscreenBtn = document.getElementById('fullscreenBtn');
const prevBtn = document.getElementById('prevBtn');
const nextBtn = document.getElementById('nextBtn');
// Store gallery images data
let galleryImages = [];
let currentImageIndex = 0;
// Example URL for user convenience
imageUrlInput.value = 'https://picsum.photos/id/237/600/400';
generateBtn.addEventListener('click', generateGallery);
imageUrlInput.addEventListener('keyup', function(event) {
if (event.key === 'Enter') {
generateGallery();
}
});
// Lightbox event listeners
closeBtn.addEventListener('click', closeLightbox);
fullscreenBtn.addEventListener('click', openFullscreen);
prevBtn.addEventListener('click', showPrevImage);
nextBtn.addEventListener('click', showNextImage);
// Close lightbox when clicking outside the image
lightbox.addEventListener('click', function(event) {
if (event.target === lightbox) {
closeLightbox();
}
});
// Keyboard navigation
document.addEventListener('keydown', function(event) {
if (lightbox.style.display === 'flex') {
if (event.key === 'Escape') closeLightbox();
if (event.key === 'ArrowLeft') showPrevImage();
if (event.key === 'ArrowRight') showNextImage();
}
});
function generateGallery() {
const baseUrl = imageUrlInput.value.trim();
// Validate input
if (!baseUrl) {
showError('Please enter an image URL');
return;
}
// Check if URL ends with a number and extension
const pattern = /(\d+)\.(jpg|jpeg|png|gif|webp)$/i;
if (!pattern.test(baseUrl)) {
showError('URL must end with a number and image extension (e.g., 06.jpg)');
return;
}
// Clear any previous errors
hideError();
// Show loading indicator
loadingIndicator.style.display = 'block';
// Clear gallery with fade out effect
imageGallery.style.opacity = '0';
setTimeout(() => {
imageGallery.innerHTML = '';
imageGallery.style.opacity = '1';
// Generate image URLs from 01 to 16
const matches = baseUrl.match(pattern);
const numberPart = matches[1];
const extension = matches[2];
const basePath = baseUrl.replace(numberPart + '.' + extension, '');
// Reset gallery images array
galleryImages = [];
// Generate gallery items
for (let i = 1; i <= 16; i++) {
const num = i.toString().padStart(2, '0');
const imgUrl = `${basePath}${num}.${extension}`;
const imgFilename = `${num}.${extension}`;
// Store image data for lightbox
galleryImages.push({
url: imgUrl,
filename: imgFilename
});
const galleryItem = document.createElement('div');
galleryItem.className = 'gallery-item';
galleryItem.dataset.index = i - 1;
galleryItem.innerHTML = `
<div class="image-container">
<img src="${imgUrl}" alt="Gallery image ${num}" onerror="handleImageError(this)">
</div>
<div class="image-info">
<div class="image-filename">${imgFilename}</div>
<div class="image-url">${imgUrl}</div>
</div>
`;
// Add click event to open lightbox
galleryItem.addEventListener('click', function() {
openLightbox(parseInt(this.dataset.index));
});
imageGallery.appendChild(galleryItem);
}
// Hide loading indicator
loadingIndicator.style.display = 'none';
}, 300);
}
function handleImageError(img) {
const container = img.parentElement;
container.innerHTML = '<div class="placeholder"><i class="fas fa-ban"></i><p>Image not found</p></div>';
container.style.cursor = 'default';
container.closest('.gallery-item').style.cursor = 'default';
}
function openLightbox(index) {
currentImageIndex = index;
const imgData = galleryImages[currentImageIndex];
lightboxImg.src = imgData.url;
lightboxImg.alt = `Enlarged view of ${imgData.filename}`;
lightboxInfo.textContent = imgData.filename;
lightbox.style.display = 'flex';
document.body.style.overflow = 'hidden';
}
function closeLightbox() {
lightbox.style.display = 'none';
document.body.style.overflow = 'auto';
}
function openFullscreen() {
const imgData = galleryImages[currentImageIndex];
window.open(imgData.url, '_blank');
}
function showPrevImage() {
currentImageIndex = (currentImageIndex - 1 + galleryImages.length) % galleryImages.length;
updateLightboxImage();
}
function showNextImage() {
currentImageIndex = (currentImageIndex + 1) % galleryImages.length;
updateLightboxImage();
}
function updateLightboxImage() {
const imgData = galleryImages[currentImageIndex];
// Add fade transition
lightboxImg.style.opacity = '0';
setTimeout(() => {
lightboxImg.src = imgData.url;
lightboxImg.alt = `Enlarged view of ${imgData.filename}`;
lightboxInfo.textContent = imgData.filename;
lightboxImg.style.opacity = '1';
}, 300);
}
function showError(message) {
errorMessage.textContent = message;
errorMessage.style.display = 'block';
}
function hideError() {
errorMessage.style.display = 'none';
}
});
</script>
</body>
</html>