File size: 24,555 Bytes
417b355 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Photo Gallery</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;
}
:root {
--primary-color: #4a6fa5;
--secondary-color: #166088;
--accent-color: #4fc3f7;
--light-color: #f8f9fa;
--dark-color: #343a40;
--shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
--transition: all 0.3s ease;
}
body {
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
color: var(--dark-color);
line-height: 1.6;
min-height: 100vh;
}
header {
background: linear-gradient(to right, var(--primary-color), var(--secondary-color));
color: white;
padding: 1.5rem 2rem;
box-shadow: var(--shadow);
position: sticky;
top: 0;
z-index: 100;
}
.header-content {
display: flex;
justify-content: space-between;
align-items: center;
max-width: 1200px;
margin: 0 auto;
}
.logo {
display: flex;
align-items: center;
gap: 10px;
}
.logo i {
font-size: 1.8rem;
}
.logo h1 {
font-size: 1.8rem;
font-weight: 700;
}
.anycoder-link {
color: white;
text-decoration: none;
font-size: 0.9rem;
opacity: 0.8;
transition: var(--transition);
}
.anycoder-link:hover {
opacity: 1;
text-decoration: underline;
}
main {
max-width: 1200px;
margin: 2rem auto;
padding: 0 1.5rem;
}
.gallery-controls {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 2rem;
flex-wrap: wrap;
gap: 1rem;
}
.search-box {
display: flex;
background: white;
border-radius: 30px;
padding: 0.5rem 1rem;
box-shadow: var(--shadow);
flex: 1;
max-width: 400px;
}
.search-box input {
border: none;
outline: none;
padding: 0.5rem;
width: 100%;
font-size: 1rem;
}
.search-box button {
background: none;
border: none;
color: var(--primary-color);
cursor: pointer;
font-size: 1.2rem;
}
.category-filter {
display: flex;
gap: 0.5rem;
flex-wrap: wrap;
}
.category-btn {
background: white;
border: none;
padding: 0.5rem 1rem;
border-radius: 20px;
font-weight: 500;
cursor: pointer;
transition: var(--transition);
box-shadow: var(--shadow);
}
.category-btn:hover, .category-btn.active {
background: var(--primary-color);
color: white;
}
.upload-btn {
background: var(--accent-color);
color: white;
border: none;
padding: 0.7rem 1.5rem;
border-radius: 30px;
font-weight: 600;
cursor: pointer;
display: flex;
align-items: center;
gap: 0.5rem;
transition: var(--transition);
box-shadow: var(--shadow);
}
.upload-btn:hover {
background: #03a9f4;
transform: translateY(-2px);
}
.gallery-container {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
gap: 1.5rem;
}
.photo-card {
background: white;
border-radius: 12px;
overflow: hidden;
box-shadow: var(--shadow);
transition: var(--transition);
cursor: pointer;
}
.photo-card:hover {
transform: translateY(-5px);
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15);
}
.photo-img {
width: 100%;
height: 200px;
object-fit: cover;
display: block;
}
.photo-details {
padding: 1rem;
}
.photo-title {
font-weight: 600;
margin-bottom: 0.5rem;
font-size: 1.1rem;
}
.photo-description {
color: #666;
font-size: 0.9rem;
margin-bottom: 1rem;
}
.photo-meta {
display: flex;
justify-content: space-between;
align-items: center;
font-size: 0.8rem;
color: #888;
}
.photo-actions {
display: flex;
gap: 0.8rem;
}
.action-btn {
background: none;
border: none;
color: #888;
cursor: pointer;
transition: var(--transition);
}
.action-btn:hover {
color: var(--primary-color);
}
.modal {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.8);
z-index: 1000;
justify-content: center;
align-items: center;
padding: 1rem;
}
.modal-content {
background: white;
border-radius: 12px;
max-width: 800px;
width: 100%;
max-height: 90vh;
overflow: hidden;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}
.modal-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 1rem 1.5rem;
border-bottom: 1px solid #eee;
}
.modal-title {
font-weight: 600;
font-size: 1.2rem;
}
.close-btn {
background: none;
border: none;
font-size: 1.5rem;
cursor: pointer;
color: #888;
}
.modal-body {
padding: 1.5rem;
max-height: calc(90vh - 120px);
overflow-y: auto;
}
.modal-img {
width: 100%;
border-radius: 8px;
margin-bottom: 1rem;
}
.modal-description {
margin-bottom: 1rem;
}
.modal-meta {
display: flex;
justify-content: space-between;
color: #666;
font-size: 0.9rem;
}
.upload-modal {
display: none;
}
.upload-form {
display: flex;
flex-direction: column;
gap: 1rem;
}
.form-group {
display: flex;
flex-direction: column;
gap: 0.5rem;
}
.form-group label {
font-weight: 500;
}
.form-group input, .form-group textarea, .form-group select {
padding: 0.8rem;
border: 1px solid #ddd;
border-radius: 6px;
font-family: inherit;
}
.form-group textarea {
min-height: 100px;
resize: vertical;
}
.submit-btn {
background: var(--primary-color);
color: white;
border: none;
padding: 0.8rem 1.5rem;
border-radius: 6px;
font-weight: 600;
cursor: pointer;
transition: var(--transition);
}
.submit-btn:hover {
background: var(--secondary-color);
}
.file-input-container {
position: relative;
display: inline-block;
width: 100%;
}
.file-input {
position: absolute;
left: 0;
top: 0;
opacity: 0;
width: 100%;
height: 100%;
cursor: pointer;
}
.file-input-label {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 2rem;
border: 2px dashed #ddd;
border-radius: 6px;
cursor: pointer;
transition: var(--transition);
text-align: center;
}
.file-input-label:hover {
border-color: var(--primary-color);
background: rgba(74, 111, 165, 0.05);
}
.file-input-label i {
font-size: 2rem;
color: #888;
margin-bottom: 0.5rem;
}
footer {
background: var(--dark-color);
color: white;
text-align: center;
padding: 1.5rem;
margin-top: 3rem;
}
@media (max-width: 768px) {
.header-content {
flex-direction: column;
gap: 1rem;
text-align: center;
}
.gallery-controls {
flex-direction: column;
align-items: stretch;
}
.search-box {
max-width: 100%;
}
.category-filter {
justify-content: center;
}
.gallery-container {
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
}
}
@media (max-width: 480px) {
.gallery-container {
grid-template-columns: 1fr;
}
.modal-content {
margin: 1rem;
}
}
</style>
</head>
<body>
<header>
<div class="header-content">
<div class="logo">
<i class="fas fa-camera"></i>
<h1>Photo Gallery</h1>
</div>
<a href="https://huggingface.co/spaces/akhaliq/anycoder" class="anycoder-link" target="_blank">Built with anycoder</a>
</div>
</header>
<main>
<div class="gallery-controls">
<div class="search-box">
<input type="text" placeholder="Search photos...">
<button><i class="fas fa-search"></i></button>
</div>
<div class="category-filter">
<button class="category-btn active">All</button>
<button class="category-btn">Nature</button>
<button class="category-btn">Portrait</button>
<button class="category-btn">Urban</button>
<button class="category-btn">Abstract</button>
</div>
<button class="upload-btn" id="openUploadModal">
<i class="fas fa-cloud-upload-alt"></i>
Upload Photo
</button>
</div>
<div class="gallery-container" id="gallery">
<!-- Photos will be dynamically added here -->
</div>
</main>
<!-- Photo Detail Modal -->
<div class="modal" id="photoModal">
<div class="modal-content">
<div class="modal-header">
<h2 class="modal-title" id="modalPhotoTitle">Photo Title</h2>
<button class="close-btn" id="closeModal">×</button>
</div>
<div class="modal-body">
<img id="modalPhotoImg" src="" alt="" class="modal-img">
<p class="modal-description" id="modalPhotoDescription">Photo description</p>
<div class="modal-meta">
<span id="modalPhotoDate">Date</span>
<span id="modalPhotoCategory">Category</span>
</div>
</div>
</div>
</div>
<!-- Upload Modal -->
<div class="modal upload-modal" id="uploadModal">
<div class="modal-content">
<div class="modal-header">
<h2 class="modal-title">Upload New Photo</h2>
<button class="close-btn" id="closeUploadModal">×</button>
</div>
<div class="modal-body">
<form class="upload-form" id="uploadForm">
<div class="form-group">
<label for="photoTitle">Photo Title</label>
<input type="text" id="photoTitle" placeholder="Enter photo title" required>
</div>
<div class="form-group">
<label for="photoDescription">Description</label>
<textarea id="photoDescription" placeholder="Enter photo description"></textarea>
</div>
<div class="form-group">
<label for="photoCategory">Category</label>
<select id="photoCategory">
<option value="nature">Nature</option>
<option value="portrait">Portrait</option>
<option value="urban">Urban</option>
<option value="abstract">Abstract</option>
</select>
</div>
<div class="form-group">
<label>Upload Photo</label>
<div class="file-input-container">
<input type="file" id="photoFile" class="file-input" accept="image/*" required>
<label for="photoFile" class="file-input-label">
<i class="fas fa-cloud-upload-alt"></i>
<span>Click to upload or drag and drop</span>
<small>PNG, JPG, GIF up to 5MB</small>
</label>
</div>
</div>
<button type="submit" class="submit-btn">Upload Photo</button>
</form>
</div>
</div>
</div>
<footer>
<p>© 2023 Photo Gallery App. All rights reserved.</p>
</footer>
<script>
// Sample photo data with real image URLs from Picsum
const photos = [
{
id: 1,
title: "Mountain Landscape",
description: "A breathtaking view of snow-capped mountains during sunset.",
category: "nature",
date: "2023-05-15",
imageUrl: "https://picsum.photos/id/1018/600/400",
likes: 42,
views: 128
},
{
id: 2,
title: "Urban Architecture",
description: "Modern city buildings with unique geometric patterns.",
category: "urban",
date: "2023-06-22",
imageUrl: "https://picsum.photos/id/1015/600/400",
likes: 28,
views: 95
},
{
id: 3,
title: "Portrait in Nature",
description: "A thoughtful portrait taken in a natural forest setting.",
category: "portrait",
date: "2023-04-10",
imageUrl: "https://picsum.photos/id/1011/600/400",
likes: 56,
views: 210
},
{
id: 4,
title: "Abstract Patterns",
description: "Colorful abstract patterns created with digital art techniques.",
category: "abstract",
date: "2023-07-05",
imageUrl: "https://picsum.photos/id/1019/600/400",
likes: 37,
views: 143
},
{
id: 5,
title: "Coastal View",
description: "Serene coastal landscape with rocky shores and crashing waves.",
category: "nature",
date: "2023-05-30",
imageUrl: "https://picsum.photos/id/1005/600/400",
likes: 64,
views: 187
},
{
id: 6,
title: "City Lights",
description: "Vibrant cityscape at night with illuminated buildings and streets.",
category: "urban",
date: "2023-06-18",
imageUrl: "https://picsum.photos/id/1016/600/400",
likes: 49,
views: 165
},
{
id: 7,
title: "Floral Close-up",
description: "Macro photography of delicate flowers with intricate details.",
category: "nature",
date: "2023-04-25",
imageUrl: "https://picsum.photos/id/1020/600/400",
likes: 71,
views: 234
},
{
id: 8,
title: "Minimalist Portrait",
description: "Clean and simple portrait with emphasis on facial expressions.",
category: "portrait",
date: "2023-07-12",
imageUrl: "https://picsum.photos/id/1025/600/400",
likes: 33,
views: 112
}
];
// DOM elements
const galleryContainer = document.getElementById('gallery');
const photoModal = document.getElementById('photoModal');
const uploadModal = document.getElementById('uploadModal');
const closeModalBtn = document.getElementById('closeModal');
const closeUploadModalBtn = document.getElementById('closeUploadModal');
const openUploadModalBtn = document.getElementById('openUploadModal');
const uploadForm = document.getElementById('uploadForm');
const searchInput = document.querySelector('.search-box input');
const categoryButtons = document.querySelectorAll('.category-btn');
// Initialize gallery
function initGallery() {
renderPhotos(photos);
}
// Render photos to the gallery
function renderPhotos(photosArray) {
galleryContainer.innerHTML = '';
photosArray.forEach(photo => {
const photoCard = document.createElement('div');
photoCard.className = 'photo-card';
photoCard.innerHTML = `
<img src="${photo.imageUrl}" alt="${photo.title}" class="photo-img">
<div class="photo-details">
<h3 class="photo-title">${photo.title}</h3>
<p class="photo-description">${photo.description}</p>
<div class="photo-meta">
<span>${photo.date}</span>
<div class="photo-actions">
<button class="action-btn"><i class="far fa-heart"></i> ${photo.likes}</button>
<button class="action-btn"><i class="far fa-eye"></i> ${photo.views}</button>
</div>
</div>
</div>
`;
photoCard.addEventListener('click', () => openPhotoModal(photo));
galleryContainer.appendChild(photoCard);
});
}
// Open photo modal with details
function openPhotoModal(photo) {
document.getElementById('modalPhotoTitle').textContent = photo.title;
document.getElementById('modalPhotoImg').src = photo.imageUrl;
document.getElementById('modalPhotoImg').alt = photo.title;
document.getElementById('modalPhotoDescription').textContent = photo.description;
document.getElementById('modalPhotoDate').textContent = `Uploaded: ${photo.date}`;
document.getElementById('modalPhotoCategory').textContent = `Category: ${photo.category.charAt(0).toUpperCase() + photo.category.slice(1)}`;
photoModal.style.display = 'flex';
}
// Open upload modal
function openUploadModal() {
uploadModal.style.display = 'flex';
}
// Close modals
function closeModals() {
photoModal.style.display = 'none';
uploadModal.style.display = 'none';
}
// Filter photos by category
function filterByCategory(category) {
if (category === 'all') {
renderPhotos(photos);
} else {
const filteredPhotos = photos.filter(photo => photo.category === category);
renderPhotos(filteredPhotos);
}
}
// Search photos
function searchPhotos(query) {
const filteredPhotos = photos.filter(photo =>
photo.title.toLowerCase().includes(query.toLowerCase()) ||
photo.description.toLowerCase().includes(query.toLowerCase())
);
renderPhotos(filteredPhotos);
}
// Handle photo upload
function handlePhotoUpload(event) {
event.preventDefault();
const title = document.getElementById('photoTitle').value;
const description = document.getElementById('photoDescription').value;
const category = document.getElementById('photoCategory').value;
const fileInput = document.getElementById('photoFile');
if (fileInput.files.length > 0) {
const file = fileInput.files[0];
const reader = new FileReader();
reader.onload = function(e) {
const newPhoto = {
id: photos.length + 1,
title: title,
description: description,
category: category,
date: new Date().toISOString().split('T')[0],
imageUrl: e.target.result,
likes: 0,
views: 0
};
photos.unshift(newPhoto);
renderPhotos(photos);
closeModals();
uploadForm.reset();
// Show success message
alert('Photo uploaded successfully!');
};
reader.readAsDataURL(file);
}
}
// Event listeners
closeModalBtn.addEventListener('click', closeModals);
closeUploadModalBtn.addEventListener('click', closeModals);
openUploadModalBtn.addEventListener('click', openUploadModal);
uploadForm.addEventListener('submit', handlePhotoUpload);
// Close modal when clicking outside
window.addEventListener('click', (event) => {
if (event.target === photoModal || event.target === uploadModal) {
closeModals();
}
});
// Category filter event listeners
categoryButtons.forEach(button => {
button.addEventListener('click', () => {
// Remove active class from all buttons
categoryButtons.forEach(btn => btn.classList.remove('active'));
// Add active class to clicked button
button.classList.add('active');
// Filter photos
filterByCategory(button.textContent.toLowerCase());
});
});
// Search functionality
searchInput.addEventListener('input', (event) => {
searchPhotos(event.target.value);
});
// Initialize the gallery
document.addEventListener('DOMContentLoaded', initGallery);
</script>
</body>
</html> |