在这篇教程中,我们将展示如何创建一个带有动态背景的 ACG(Anime, Comic, Game)网页。这个网页将包含一个视频背景,并在移动设备上自动切换为图片背景。此外,我们还将添加一些有趣的鼠标特效,使网页更具互动性。

HTML 结构

首先,我们需要设置基本的 HTML 结构:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ACG Background</title>
<link rel="icon" href="https://server.universex.space/ota/Lemon/iK04ZZoY.png" type="image/x-icon">
<style>
/* 在此处添加 CSS 样式 */
</style>
</head>
<body>
<video id="bg-video" autoplay loop muted>
<source src="https://t.alcy.cc/acg" type="video/mp4">
Your browser does not support the video tag.
</video>
<div class="content">
<!-- 页面内容放在这里 -->
<h1>欢迎来到我的ACG网页</h1>
<p>这是一个示例网页,展示如何创建带有动态背景和特效的页面。</p>
</div>
<script>
/* 在此处添加 JavaScript 代码 */
</script>
</body>
</html>

添加 CSS 样式

接下来,我们需要为页面添加一些 CSS 样式,以实现视频背景、屏幕适配和其他样式设置。

/* 屏幕适配 */
@media only screen and (min-width: 767px) {
.ui.container {
width: 85% !important;
}
}

@media only screen and (max-width: 767px) {
.ui.card > .content > .header:not(.ui),
.ui.cards > .card > .content > .header:not(.ui) {
margin-top: 0.4em !important;
}

/* 使用图片背景代替视频背景 */
body, html {
background: url('https://t.alcy.cc/ycy') no-repeat center center fixed;
background-size: cover;
}
}

/* 动态背景视频 */
body, html {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
overflow: auto; /* 允许页面滚动 */
background: url('https://t.alcy.cc/ycy') no-repeat center center fixed;
background-size: cover;
}

#bg-video {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
object-fit: cover;
z-index: -1;
}

.content {
position: relative;
z-index: 1;
font-family: Arial, Helvetica, sans-serif;
}

/* 导航栏 */
.ui.large.menu {
border: 0 !important;
border-radius: 0px !important;
background-color: rgba(255, 255, 255, 55%) !important;
}

/* 首页按钮 */
.ui.menu .active.item {
background-color: transparent !important;
}

/* 导航栏下拉框 */
.ui.ui.dropdown .menu {
border: 0 !important;
border-radius: 0 !important;
background-color: rgba(255, 255, 255, 80%) !important;
}

/* 登陆按钮(需要使用配套自定义主题) */
.nezha-primary-btn {
background-color: rgba(255, 255, 255, 0.8) !important;
color: #000 !important;
}

.mochen-primary-btn {
background-color: rgba(255, 255, 255, 0.8) !important;
color: #000 !important;
border-radius: 1rem !important;
transition: all 0.5s;
}

.mochen-primary-btn:hover {
background-color: rgba(247, 199, 111, 0.8) !important;
color: #000 !important;
border-radius: 1rem !important;
}

/* 大卡片 */
#app .ui.fluid.accordion {
background-color: #fbfbfb26 !important;
border-radius: 0.4rem !important;
}

/* 小卡片 */
.ui.four.cards > .card {
border-radius: 0.6rem !important;
background-color: #fafafaa3 !important;
}

/* 其他样式省略 */

添加 JavaScript 代码

接下来,我们需要添加一些 JavaScript 代码来实现页面加载时的效果、背景视频错误处理以及鼠标特效。

window.onload = function() {
var avatar = document.querySelector(".item img");
var footer = document.querySelector("div.is-size-7");
footer.innerHTML = "Lemonmia";
footer.style.visibility = "visible";
avatar.src = "https://server.universex.space/ota/Lemon/iK04ZZoY.png";
avatar.style.visibility = "visible";
}
var faviconurl = "https://server.universex.space/ota/Lemon/iK04ZZoY.png"; 
var link = document.querySelector("link[rel*='icon']") || document.createElement('link');
link.type = 'image/x-icon';
link.rel = 'shortcut icon';
link.href = faviconurl;
document.getElementsByTagName('head')[0].appendChild(link);

// 检查视频是否加载失败
var video = document.getElementById('bg-video');
video.onerror = function() {
document.body.style.backgroundImage = "url('https://t.alcy.cc/ycy')";
document.body.style.backgroundSize = "cover";
};

// 动态切换背景视频和图片
if (window.innerWidth <= 767) {
document.getElementById('bg-video').style.display = 'none';
document.body.style.backgroundImage = "url('https://t.alcy.cc/ycy')";
document.body.style.backgroundSize = "cover";
}

添加网页特效

为了让网页更有趣,我们可以添加一些特效,如樱花、爱心、烟花波纹和小星星拖尾效果。我们可以通过引入外部 JavaScript 文件来实现这些效果。

<!-- 网页特效 - 樱花 -->
<script src="https://cdn.jsdelivr.net/gh/mocchen/cssmeihua/js/yinghua.js"></script>

<!-- 网页鼠标点击特效 - 爱心 -->
<script src="https://cdn.jsdelivr.net/gh/mocchen/cssmeihua/js/aixin.js"></script>

<!-- 网页鼠标点击特效 - 烟花波纹 -->
<script src="https://cdn.jsdelivr.net/gh/mocchen/cssmeihua/js/yanhuabowen.js"></script>

<!-- 鼠标特效 - 小星星拖尾 -->
<span class="js-cursor-container"></span>
<script src="https://cdn.jsdelivr.net/gh/mocchen/cssmeihua/js/xiaoxingxing.js"></script>

代码整合

      在最后提供一个整合代码,可直接复制粘贴到自己的css使用
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ACG Background</title>
<style>
/* 屏幕适配 */
@media only screen and (min-width: 767px) {
.ui.container {
width: 85% !important;
}
}

@media only screen and (max-width: 767px) {
.ui.card > .content > .header:not(.ui),
.ui.cards > .card > .content > .header:not(.ui) {
margin-top: 0.4em !important;
}

/* 使用图片背景代替视频背景 */
body, html {
background: url('https://t.alcy.cc/ycy') no-repeat center center fixed;
background-size: cover;
}
}

/* 动态背景视频 */
body, html {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
overflow: auto; /* 允许页面滚动 */
background: url('https://t.alcy.cc/ycy') no-repeat center center fixed;
background-size: cover;
}

#bg-video {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
object-fit: cover;
z-index: -1;
}

.content {
position: relative;
z-index: 1;
font-family: Arial, Helvetica, sans-serif;
}

/* 导航栏 */
.ui.large.menu {
border: 0 !important;
border-radius: 0px !important;
background-color: rgba(255, 255, 255, 55%) !important;
}

/* 首页按钮 */
.ui.menu .active.item {
background-color: transparent !important;
}

/* 导航栏下拉框 */
.ui.ui.dropdown .menu {
border: 0 !important;
border-radius: 0 !important;
background-color: rgba(255, 255, 255, 80%) !important;
}

/* 登陆按钮(需要使用配套自定义主题) */
.nezha-primary-btn {
background-color: rgba(255, 255, 255, 0.8) !important;
color: #000 !important;
}

.mochen-primary-btn {
background-color: rgba(255, 255, 255, 0.8) !important;
color: #000 !important;
border-radius: 1rem !important;
transition: all 0.5s;
}

.mochen-primary-btn:hover {
background-color: rgba(247, 199, 111, 0.8) !important;
color: #000 !important;
border-radius: 1rem !important;
}

/* 大卡片 */
#app .ui.fluid.accordion {
background-color: #fbfbfb26 !important;
border-radius: 0.4rem !important;
}

/* 小卡片 */
.ui.four.cards > .card {
border-radius: 0.6rem !important;
background-color: #fafafaa3 !important;
}

.status.cards .wide.column {
padding-top: 0 !important;
padding-bottom: 0 !important;
height: 2.3rem !important;
}

.status.cards .thirteen.wide.column {
padding-left: 0rem !important;
padding-right: 1.4rem !important;
}

.status.cards .three.wide.column {
padding-left: 1.4rem !important;
padding-right: 0rem !important;
}

.status.cards .wide.column:nth-child(1) {
margin-top: 2rem !important;
}

.status.cards .wide.column:nth-child(2) {
margin-top: 2rem !important;
}

.status.cards .description {
padding-bottom: 0 !important;
}

/* 弹出卡片图标 */
.status.cards .header > .info.icon {
margin-right: 0 !important;
}

.nezha-secondary-font {
color: #21ba45 !important;
}

/* 进度条 */
.ui.progress {
border-radius: 50rem !important;
}

.ui.progress .bar {
min-width: 1.8em !important;
border-radius: 15px !important;
line-height: 1.65em !important;
}

.ui.fine.progress > .bar {
background-color: #21ba45 !important;
}

.ui.progress > .bar {
background-color: #000 !important;
}

.ui.progress.fine .bar {
background-color: #21ba45 !important;
}

.ui.progress.warning .bar {
background-color: #ff9800 !important;
}

.ui.progress.error .bar {
background-color: #e41e10 !important;
}

.ui.progress.offline .bar {
background-color: #000 !important;
}

/* 上传下载 */
.status.cards .outline.icon {
margin-right: 1px !important;
}

i.arrow.alternate.circle.down.outline.icon {
color: #21ba45 !important;
}

i.arrow.alternate.circle.up.outline.icon {
color: red !important;
}

/* 弹出卡片小箭头 */
.ui.right.center.popup {
margin: -3px 0 0 0.914286em !important;
-webkit-transform-origin: left 50% !important;
transform-origin: left 50% !important;
}

.ui.bottom.left.popup {
margin-left: 1px !important;
margin-top: 3px !important;
}

.ui.top.left.popup {
margin-left: 0 !important;
margin-bottom: 10px !important;
}

.ui.top.right.popup {
margin-right: 0 !important;
margin-bottom: 8px !重要;
}

.ui.left.center.popup {
margin: -3px .91428571em 0 0 !重要;
-webkit-transform-origin: right 50% !重要;
transform-origin: right 50% !重要;
}

.ui.right.center.popup:before,
.ui.left.center.popup:before {
border: 0px solid #fafafaeb !重要;
background: #fafafaeb !重要;
}

.ui.top.popup:before {
border-color: #fafafaeb transparent transparent !重要;
}

.ui.popup:before {
border-color: #fafafaeb transparent transparent !重要;
}

.ui.bottom.left.popup:before {
border-radius: 0 !重要;
border: 1px solid transparent !重要;
border-color: #fafafaeb transparent transparent !重要;
background: #fafafaeb !重要;
-webkit-box-shadow: 0px 0px 0 0 #fafafaeb !重要;
box-shadow: 0px 0px 0 0 #fafafaeb !重要;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0) !重要;
}

.ui.bottom.right.popup:before {
border-radius: 0 !重要;
border: 1px solid transparent !重要;
border-color: #fafafaeb transparent transparent !重要;
background: #fafafaeb !重要;
-webkit-box-shadow: 0px 0px 0 0 #fafafaeb !重要;
box-shadow: 0px 0px 0 0 #fafafaeb !重要;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0) !重要;
}

.ui.top.left.popup:before {
border-radius: 0 !重要;
border: 1px solid transparent !重要;
border-color: #fafafaeb transparent transparent !重要;
background: #fafafaeb !重要;
-webkit-box-shadow: 0px 0px 0 0 #fafafaeb !重要;
box-shadow: 0px 0px 0 0 #fafafaeb !重要;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0) !重要;
}

.ui.top.right.popup:before {
border-radius: 0 !重要;
border: 1px solid transparent !重要;
border-color: #fafafaeb transparent transparent !重要;
background: #fafafaeb !重要;
-webkit-box-shadow: 0px 0px 0 0 #fafafaeb !重要;
box-shadow: 0px 0px 0 0 #fafafaeb !重要;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0) !重要;
}

.ui.left.center.popup:before {
border-radius: 0 !重要;
border: 1px solid transparent !重要;
border-color: #fafafaeb transparent transparent !重要;
background: #fafafaeb !重要;
-webkit-box-shadow: 0px 0px 0 0 #fafafaeb !重要;
box-shadow: 0px 0px 0 0 #fafafaeb !重要;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0) !重要;
}

/* 弹出卡片 */
.status.cards .ui.content.popup {
min-width: 20rem !重要;
line-height: 2rem !重要;
border-radius: 5px !重要;
border: 1px solid transparent !重要;
background-color: #fafafaeb !重要;
font-family: Arial, Helvetica, sans-serif !重要;
}

.ui.content {
margin: 0 !重要;
padding: 1em !重要;
}

/* 服务页 */
.ui.table {
background: RGB(225, 225, 225, 0.6) !重要;
}

.ui.table thead th {
background: transparent !重要;
}

/* 服务页进度条 */
.service-status .good {
background-color: #21ba45 !重要;
}

.service-status .danger {
background-color: red !重要;
}

.service-status .warning {
background-color: orange !重要;
}

/*鼠标*/
body {
cursor: url(https://raw.githubusercontent.com/mocchen/cssmeihua/mochen/a.cur), default;
}

/* 版权 */
.ui.inverted.segment,
.ui.primary.inverted.segment {
color: #000 !重要;
font-weight: bold !重要;
background-color: #fafafaa3 !重要;
}
</style>
</head>
<body>
<video id="bg-video" autoplay loop muted>
<source src="https://t.alcy.cc/acg" type="video/mp4">
Your browser does not support the video tag.
</video>
<div class="content">
<!-- 页面内容放在这里 -->
<h1></h1>
<p></p>
</div>

<!--Logo和版权-->
<script>
window.onload = function() {
var avatar = document.querySelector(".item img");
var footer = document.querySelector("div.is-size-7");
footer.innerHTML = "Lemonmia";
footer.style.visibility = "visible";
avatar.src = "https://server.universex.space/ota/Lemon/iK04ZZoY.png";
avatar.style.visibility = "visible";
}
var faviconurl = "https://server.universex.space/ota/Lemon/iK04ZZoY.png"; 
var link = document.querySelector("link[rel*='icon']") || document.createElement('link');
link.type = 'image/x-icon';
link.rel = 'shortcut icon';
link.href = faviconurl;
document.getElementsByTagName('head')[0].appendChild(link);

// 检查视频是否加载失败
var video = document.getElementById('bg-video');
video.onerror = function() {
document.body.style.backgroundImage = "url('https://t.alcy.cc/ycy')";
document.body.style.backgroundSize = "cover";
};
</script>

<!-- 网页特效 - 樱花 -->
<script src="https://cdn.jsdelivr.net/gh/mocchen/cssmeihua/js/yinghua.js"></script>

<!-- 网页鼠标点击特效 - 爱心 -->
<script src="https://cdn.jsdelivr.net/gh/mocchen/cssmeihua/js/aixin.js"></script>

<!-- 网页鼠标点击特效 - 烟花波纹 -->
<script src="https://cdn.jsdelivr.net/gh/mocchen/cssmeihua/js/yanhuabowen.js"></script>

<!-- 鼠标特效 - 小星星拖尾 -->
<span class="js-cursor-container"></span>
<script src="https://cdn.jsdelivr.net/gh/mocchen/cssmeihua/js/xiaoxingxing.js"></script>

<script src="https://fastly.jsdelivr.net/gh/stevenjoezhang/live2d-widget@latest/autoload.js"></script>

<script>
// 动态切换背景视频和图片
if (window.innerWidth <= 767) {
document.getElementById('bg-video').style.display = 'none';
document.body.style.backgroundImage = "url('https://t.alcy.cc/ycy')";
document.body.style.backgroundSize = "cover";
}
</script>
</body>
</html>

总结

通过以上步骤,我们创建了一个带有动态背景视频的哪吒监控看板,并确保在视频加载失败时切换为静态背景图片。这样的设计不仅增强了哪吒监控看板的视觉效果,还提高了访问体验的稳定性!

这里使用了栗次元大佬提供的API

Lemon