/
maybeyoou
/
pic
Обзор
Документация
Войти
/
maybeyoou
/
pic
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
index.html
185 строк
5 KB
Maybeoff
pic
28 июн 2026, 20:42
28 июн 2026, 20:42
83c7f5a
Код
Авторство
О чём код?
<!DOCTYPE html> <html lang="ru"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Индекс изображений</title> <style> body { font-family: Arial, sans-serif; padding: 20px; background-color: #f5f5f5; margin: 0; } h1 { text-align: center; color: #333; } .gallery { display: flex; flex-wrap: wrap; gap: 20px; justify-content: center; } .image-card { background: white; border-radius: 8px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); padding: 15px; text-align: center; max-width: 300px; } .image-card img { max-width: 100%; height: auto; border-radius: 4px; cursor: pointer; } .image-card a { display: inline-block; margin-top: 10px; padding: 8px 16px; background-color: #007bff; color: white; text-decoration: none; border-radius: 4px; } .image-card a:hover { background-color: #0056b3; } #loading { text-align: center; font-size: 18px; color: #666; } .modal { display: none; position: fixed; z-index: 1000; left: 0; top: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.9); } .modal-content { display: block; margin: auto; max-width: 90%; max-height: 80vh; border-radius: 8px; } .close { position: absolute; top: 20px; right: 35px; color: #f1f1f1; font-size: 40px; font-weight: bold; cursor: pointer; } .close:hover { color: #bbb; } .modal-caption { color: #ddd; text-align: center; padding: 15px; font-size: 18px; } .modal-download { display: block; margin: 10px auto; padding: 10px 20px; background-color: #007bff; color: white; text-decoration: none; border-radius: 4px; max-width: 200px; } .modal-download:hover { background-color: #0056b3; } </style> </head> <body> <h1>Изображения</h1> <div id="loading">Загрузка...</div> <div class="gallery" id="gallery"></div> <!-- Модальное окно --> <div id="imageModal" class="modal"> <span class="close">×</span> <img class="modal-content" id="modalImg"> <div class="modal-caption" id="modalCaption"></div> <a class="modal-download" id="modalDownload" download>Скачать</a> </div> <script> // Читаем pic_contents.txt и генерируем HTML fetch('pic_contents.txt') .then(response => response.text()) .then(text => { const files = text.trim().split('\n').filter(line => line.trim()); const gallery = document.getElementById('gallery'); const loading = document.getElementById('loading'); if (files.length === 0) { gallery.innerHTML = '<p>Нет изображений</p>'; loading.style.display = 'none'; return; } files.forEach(filename => { if (filename.trim()) { const card = document.createElement('div'); card.className = 'image-card'; card.innerHTML = ` <img src="pic/${filename}" alt="${filename}" class="preview-img"> <br> <a href="pic/${filename}" download>Скачать</a> `; gallery.appendChild(card); } }); loading.style.display = 'none'; // Добавляем обработчики кликов для превью document.querySelectorAll('.preview-img').forEach(img => { img.addEventListener('click', function() { openModal(this.src, this.alt); }); }); }) .catch(error => { document.getElementById('gallery').innerHTML = '<p>Ошибка загрузки списка файлов</p>'; console.error('Error:', error); }); // Логика модального окна const modal = document.getElementById('imageModal'); const modalImg = document.getElementById('modalImg'); const modalCaption = document.getElementById('modalCaption'); const modalDownload = document.getElementById('modalDownload'); const closeBtn = document.querySelector('.close'); function openModal(src, alt) { modal.style.display = 'block'; modalImg.src = src; modalCaption.textContent = alt; modalDownload.href = src; } closeBtn.onclick = function() { modal.style.display = 'none'; } window.onclick = function(event) { if (event.target == modal) { modal.style.display = 'none'; } } </script> </body> </html>