好的!下面是一个非常简化的单文件 HTML 示例,模拟一个类似 Bilibili 首页的视频播放平台布局。它包含:
- 顶部导航栏
- 视频推荐网格(带封面图、标题、播放按钮)
- 点击播放按钮时,页面中间弹出视频播放器播放对应视频
- 简单响应式布局和样式
你可以直接保存为 index.html,用浏览器打开体验。
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>简易Bilibili首页视频平台</title>
<style>
* {
box-sizing: border-box;
}
body {
margin: 0; font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
background: #f9f9f9;
}
header {
background: #00a1d6;
color: white;
padding: 12px 20px;
font-size: 24px;
font-weight: bold;
}
nav {
margin-top: 8px;
background: #007bb8;
padding: 8px 20px;
display: flex;
gap: 20px;
}
nav a {
color: white;
text-decoration: none;
font-weight: 600;
}
nav a:hover {
text-decoration: underline;
}
main {
max-width: 1200px;
margin: 20px auto;
padding: 0 10px;
}
.video-grid {
display: grid;
grid-template-columns: repeat(auto-fill,minmax(240px,1fr));
gap: 16px;
}
.video-card {
background: white;
border-radius: 6px;
box-shadow: 0 2px 6px rgb(0 0 0 / 0.1);
overflow: hidden;
cursor: pointer;
display: flex;
flex-direction: column;
}
.video-thumb {
position: relative;
width: 100%;
padding-top: 56.25%; /* 16:9 ratio */
background-size: cover;
background-position: center;
}
.play-button {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: rgba(0,0,0,0.6);
border-radius: 50%;
width: 48px;
height: 48px;
display: flex;
align-items: center;
justify-content: center;
}
.play-button:before {
content: "";
display: inline-block;
margin-left: 4px;
border-style: solid;
border-width: 10px 0 10px 16px;
border-color: transparent transparent transparent white;
}
.video-info {
padding: 12px 14px;
flex-grow: 1;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.video-title {
font-size: 16px;
font-weight: 600;
color: #333;
margin: 0 0 8px 0;
line-height: 1.2em;
height: 2.4em; /* 2 lines */
overflow: hidden;
text-overflow: ellipsis;
}
.video-meta {
font-size: 13px;
color: #666;
}
/* 弹出播放器遮罩 */
.overlay {
position: fixed;
top: 0; left: 0; right: 0; bottom: 0;
background: rgba(0,0,0,0.7);
display: none;
align-items: center;
justify-content: center;
z-index: 9999;
}
.overlay.active {
display: flex;
}
.player-container {
background: #000;
max-width: 90vw;
max-height: 80vh;
width: 800px;
border-radius: 8px;
overflow: hidden;
position: relative;
}
video {
width: 100%;
height: 100%;
display: block;
}
.close-btn {
position: absolute;
top: 8px;
right: 8px;
background: rgba(255,255,255,0.8);
border: none;
border-radius: 50%;
width: 32px;
height: 32px;
font-size: 20px;
font-weight: bold;
cursor: pointer;
line-height: 1;
}
.close-btn:hover {
background: white;
}
@media (max-width: 600px) {
nav {
flex-wrap: wrap;
gap: 10px;
}
.player-container {
width: 100vw;
height: 56.25vw; /* 16:9 */
max-height: none;
border-radius: 0;
}
}
</style>
</head>
<body>
<header>简易Bilibili首页</header>
<nav>
<a href="#">首页</a>
<a href="#">动画</a>
<a href="#">番剧</a>
<a href="#">游戏</a>
<a href="#">直播</a>
<a href="#">排行榜</a>
</nav>
<main>
<div class="video-grid" id="videoGrid">
<!-- 视频卡片由JS生成 -->
</div>
</main>
<!-- 弹出播放器 -->
<div class="overlay" id="videoOverlay">
<div class="player-container">
<button class="close-btn" id="closeBtn" title="关闭">×</button>
<video id="videoPlayer" controls></video>
</div>
</div>
<script>
// 模拟视频数据
const videos = [
{
title: "【官方】Bilibili 2024 新春特别节目",
thumb: "https://i0.hdslb.com/bfs/archive/1a2b3c4d5e6f7g8h9i0j.jpg",
src: "https://media.w3.org/2010/05/sintel/trailer.mp4"
},
{
title: "超燃游戏实况合集",
thumb: "https://i0.hdslb.com/bfs/archive/abcdef1234567890.jpg",
src: "https://media.w3.org/2010/05/bunny/trailer.mp4"
},
{
title: "热门动画片段精选",
thumb: "https://i0.hdslb.com/bfs/archive/123456abcdef7890.jpg",
src: "https://media.w3.org/2010/05/video/movie_300.mp4"
},
{
title: "音乐现场演唱会",
thumb: "https://i0.hdslb.com/bfs/archive/0987654321fedcba.jpg",
src: "https://media.w3.org/2010/05/video/movie_300.mp4"
},
{
title: "科技探索纪录片",
thumb: "https://i0.hdslb.com/bfs/archive/1122334455667788.jpg",
src: "https://media.w3.org/2010/05/sintel/trailer.mp4"
},
{
title: "搞笑短视频合集",
thumb: "https://i0.hdslb.com/bfs/archive/2233445566778899.jpg",
src: "https://media.w3.org/2010/05/bunny/trailer.mp4"
}
];
const videoGrid = document.getElementById("videoGrid");
const overlay = document.getElementById("videoOverlay");
const videoPlayer = document.getElementById("videoPlayer");
const closeBtn = document.getElementById("closeBtn");
// 生成视频卡片
videos.forEach((video, index) => {
const card = document.createElement("div");
card.className = "video-card";
const thumb = document.createElement("div");
thumb.className = "video-thumb";
thumb.style.backgroundImage = `url(${video.thumb})`;
const playBtn = document.createElement("div");
playBtn.className = "play-button";
thumb.appendChild(playBtn);
const info = document.createElement("div");
info.className = "video-info";
const title = document.createElement("h3");
title.className = "video-title";
title.textContent = video.title;
info.appendChild(title);
card.appendChild(thumb);
card.appendChild(info);
// 点击播放
card.addEventListener("click", () => {
videoPlayer.src = video.src;
videoPlayer.play();
overlay.classList.add("active");
});
videoGrid.appendChild(card);
});
// 关闭播放器
closeBtn.addEventListener("click", () => {
videoPlayer.pause();
videoPlayer.src = "";
overlay.classList.remove("active");
});
// 点击遮罩关闭播放器
overlay.addEventListener("click", (e) => {
if (e.target === overlay) {
closeBtn.click();
}
});
</script>
</body>
</html>
说明:
- 视频封面图用的是示例链接(Bilibili真实封面图链接需要替换)
- 视频源用的是公开的示例视频链接(W3C提供的测试视频)
- 点击视频卡片会弹出播放器,点击关闭按钮或遮罩关闭播放器
- 布局简洁,适合做基础演示
如果你需要更复杂的功能(分页、搜索、弹幕等),可以告诉我,我帮你扩展!