This commit is contained in:
2025-12-14 11:05:06 +08:00
parent 6be9d12b75
commit acb0666840

View File

@@ -3,47 +3,148 @@ title: 海淀区合唱团表演
date: "2025-12-10"
---
<div class="video-container">
<video
controls
preload="metadata"
poster="/path/to/poster.jpg" <!-- 可选:视频封面 -->
width="100%"
style="border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.1);">
<div class="lazy-video" data-src="choir_show.mp4">
<!-- 预览图 -->
<div class="video-preview" onclick="loadAndPlay(this)">
<img src="video-thumbnail.jpg" alt="视频预览" class="preview-image">
<div class="play-button">▶</div>
<div class="video-info-overlay">
<span>点击播放视频</span>
<small>时长: 3:45</small>
</div>
</div>
<source src="choir_show.mp4" type="video/mp4">
<!-- 浏览器不支持时的备选方案 -->
<p>您的浏览器不支持 HTML5 视频。请
<a href="choir_show.mp4">下载视频</a>
</p>
<!-- 视频播放器(初始隐藏) -->
<div class="video-player" style="display: none;">
<video controls>
<source src="" type="video/mp4">
</video>
<div class="video-caption">
<p>合唱团表演视频 | 2023年音乐会</p>
<button class="close-video" onclick="closeVideo(this)">✕</button>
</div>
</div>
<script>
function loadAndPlay(element) {
const container = element.closest('.lazy-video');
const videoSrc = container.getAttribute('data-src');
const preview = container.querySelector('.video-preview');
const player = container.querySelector('.video-player');
const video = player.querySelector('video');
const source = video.querySelector('source');
// 设置视频源
source.src = videoSrc;
video.load();
// 切换显示
preview.style.display = 'none';
player.style.display = 'block';
// 开始播放
video.play();
}
function closeVideo(button) {
const player = button.closest('.video-player');
const container = player.closest('.lazy-video');
const preview = container.querySelector('.video-preview');
const video = player.querySelector('video');
// 停止播放
video.pause();
video.currentTime = 0;
// 切换显示
player.style.display = 'none';
preview.style.display = 'block';
}
</script>
<style>
.video-container {
.lazy-video {
max-width: 800px;
margin: 2rem auto;
}
video {
display: block;
.video-preview {
position: relative;
cursor: pointer;
border-radius: 8px;
overflow: hidden;
background: #000;
aspect-ratio: 16/9;
}
.video-caption {
text-align: center;
margin-top: 10px;
color: #666;
font-size: 0.9em;
.preview-image {
width: 100%;
height: 100%;
object-fit: cover;
opacity: 0.8;
transition: opacity 0.3s;
}
/* 深色模式适配 */
[data-darkmode] video {
box-shadow: 0 4px 12px rgba(0,0,0,0.3);
.video-preview:hover .preview-image {
opacity: 0.6;
}
.play-button {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 70px;
height: 70px;
background: rgba(255, 255, 255, 0.9);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 30px;
color: #007bff;
box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}
.video-info-overlay {
position: absolute;
bottom: 0;
left: 0;
right: 0;
background: linear-gradient(transparent, rgba(0,0,0,0.8));
color: white;
padding: 20px;
display: flex;
justify-content: space-between;
align-items: flex-end;
}
.video-player {
position: relative;
background: #000;
border-radius: 8px;
overflow: hidden;
}
.video-player video {
width: 100%;
height: auto;
max-height: 600px;
display: block;
}
.close-video {
position: absolute;
top: 10px;
right: 10px;
background: rgba(0,0,0,0.7);
color: white;
border: none;
width: 36px;
height: 36px;
border-radius: 50%;
cursor: pointer;
font-size: 18px;
display: flex;
align-items: center;
justify-content: center;
}
</style>