|
|
<!DOCTYPE html>
|
|
|
<html lang="en">
|
|
|
<head>
|
|
|
<meta charset="UTF-8">
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
<title>ttings</title>
|
|
|
<style>
|
|
|
body {
|
|
|
font-family: Arial, sans-serif;
|
|
|
margin: 0;
|
|
|
padding: 0;
|
|
|
display: flex;
|
|
|
justify-content: center;
|
|
|
align-items: center;
|
|
|
flex-direction: column;
|
|
|
overflow-x: hidden;
|
|
|
}
|
|
|
.gallery {
|
|
|
display: grid;
|
|
|
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
|
|
|
gap: 10px;
|
|
|
width: 100%;
|
|
|
max-width: 100vw;
|
|
|
margin: 20px 0;
|
|
|
padding: 0 10px;
|
|
|
}
|
|
|
.media {
|
|
|
position: relative;
|
|
|
overflow: hidden;
|
|
|
border-radius: 10px;
|
|
|
background-color: #f0f0f0;
|
|
|
aspect-ratio: 1 / 1;
|
|
|
}
|
|
|
.media img, .media video {
|
|
|
width: 100%;
|
|
|
height: 100%;
|
|
|
object-fit: cover;
|
|
|
border-radius: 10px;
|
|
|
cursor: pointer;
|
|
|
opacity: 0;
|
|
|
transition: opacity 0.3s, transform 0.3s;
|
|
|
}
|
|
|
.media img.loaded, .media video.loaded {
|
|
|
opacity: 1;
|
|
|
}
|
|
|
.media img:hover, .media video:hover {
|
|
|
transform: scale(1.05);
|
|
|
}
|
|
|
.filename {
|
|
|
position: absolute;
|
|
|
bottom: 5px;
|
|
|
left: 5px;
|
|
|
right: 5px;
|
|
|
background: rgba(0, 0, 0, 0.6);
|
|
|
color: white;
|
|
|
font-size: 12px;
|
|
|
text-align: center;
|
|
|
padding: 2px 5px;
|
|
|
border-radius: 5px;
|
|
|
overflow: hidden;
|
|
|
text-overflow: ellipsis;
|
|
|
white-space: nowrap;
|
|
|
}
|
|
|
.modal {
|
|
|
display: none;
|
|
|
position: fixed;
|
|
|
top: 0;
|
|
|
left: 0;
|
|
|
width: 100%;
|
|
|
height: 100%;
|
|
|
background-color: rgba(0, 0, 0, 0.8);
|
|
|
justify-content: center;
|
|
|
align-items: center;
|
|
|
z-index: 1000;
|
|
|
}
|
|
|
.modal.active {
|
|
|
display: flex;
|
|
|
}
|
|
|
.modal-content img, .modal-content video {
|
|
|
max-width: 90vw;
|
|
|
max-height: 90vh;
|
|
|
border-radius: 10px;
|
|
|
}
|
|
|
body.modal-open {
|
|
|
overflow: hidden;
|
|
|
}
|
|
|
</style>
|
|
|
</head>
|
|
|
<body>
|
|
|
|
|
|
<div class="gallery">
|
|
|
<!-- 假设这是动态渲染的静态目录文件,支持懒加载 -->
|
|
|
{% for file in files %}
|
|
|
<div class="media">
|
|
|
{% if file.endswith(('.jpg', '.jpeg', '.png', '.gif', '.JPG', '.JPEG', '.PNG', '.GIF')) %}
|
|
|
<img data-src="/media/{{ file }}" alt="{{ file }}" onclick="openModal('/media/{{ file }}', 'image')">
|
|
|
{% elif file.endswith(('.mp4', '.avi', '.mov', '.wmv', '.m4v', '.mpg')) %}
|
|
|
<video data-src="/media/{{ file }}" controls onclick="openModal('/media/{{ file }}', 'video')">
|
|
|
Your browser does not support the video tag.
|
|
|
</video>
|
|
|
{% endif %}
|
|
|
<!-- <div class="filename">{{ file }}</div> -->
|
|
|
</div>
|
|
|
{% endfor %}
|
|
|
</div>
|
|
|
|
|
|
<!-- 模态框 -->
|
|
|
<div id="modal" class="modal">
|
|
|
<div class="modal-content">
|
|
|
<img id="modal-image" src="" alt="Full view">
|
|
|
<video id="modal-video" controls>
|
|
|
Your browser does not support the video tag.
|
|
|
</video>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
<script>
|
|
|
// 使用 IntersectionObserver 进行懒加载和渐显效果
|
|
|
const mediaElements = document.querySelectorAll('.media img, .media video');
|
|
|
|
|
|
const lazyLoadObserver = new IntersectionObserver((entries, observer) => {
|
|
|
entries.forEach(entry => {
|
|
|
if (entry.isIntersecting) {
|
|
|
const mediaElement = entry.target;
|
|
|
if (mediaElement.tagName.toLowerCase() === 'img') {
|
|
|
mediaElement.src = mediaElement.dataset.src; // 加载图片
|
|
|
mediaElement.classList.add('loaded'); // 添加渐显效果
|
|
|
} else if (mediaElement.tagName.toLowerCase() === 'video') {
|
|
|
mediaElement.src = mediaElement.dataset.src; // 加载视频
|
|
|
mediaElement.classList.add('loaded'); // 添加渐显效果
|
|
|
}
|
|
|
observer.unobserve(mediaElement); // 停止观察该元素
|
|
|
}
|
|
|
});
|
|
|
}, {
|
|
|
rootMargin: '0px 0px 200px 0px' // 提前200px加载,防止延迟
|
|
|
});
|
|
|
|
|
|
// 开始观察所有的图片和视频
|
|
|
mediaElements.forEach(element => {
|
|
|
lazyLoadObserver.observe(element);
|
|
|
});
|
|
|
|
|
|
// 点击图片或视频,显示完整内容
|
|
|
const modal = document.getElementById('modal');
|
|
|
const modalImage = document.getElementById('modal-image');
|
|
|
const modalVideo = document.getElementById('modal-video');
|
|
|
const body = document.body;
|
|
|
|
|
|
function openModal(src, type) {
|
|
|
modal.classList.add('active');
|
|
|
body.classList.add('modal-open');
|
|
|
if (type === 'image') {
|
|
|
modalImage.src = src;
|
|
|
modalImage.style.display = 'block';
|
|
|
modalVideo.style.display = 'none';
|
|
|
} else if (type === 'video') {
|
|
|
modalVideo.src = src;
|
|
|
modalVideo.style.display = 'block';
|
|
|
modalImage.style.display = 'none';
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 点击空白区域关闭模态框
|
|
|
modal.addEventListener('click', () => {
|
|
|
modal.classList.remove('active');
|
|
|
body.classList.remove('modal-open');
|
|
|
modalImage.style.display = 'none';
|
|
|
modalVideo.style.display = 'none';
|
|
|
});
|
|
|
</script>
|
|
|
|
|
|
</body>
|
|
|
</html>
|