<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>毛玻璃特效导航菜单</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Arial', sans-serif;
background-color: #f5f5f5;
color: #333;
overflow-x: hidden;
}
header {
position: relative;
height: 100vh;
overflow: hidden;
}
header::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: url('https://picsum.photos/1920/1080.jpg?random=1') no-repeat center center;
background-size: cover;
z-index: -1;
filter: blur(5px);
transform: scale(1.05);
}
.content {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
z-index: 1;
}
.content h1 {
font-size: 3rem;
color: #fff;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
margin-bottom: 2rem;
}
.content p {
font-size: 1.2rem;
color: #fff;
max-width: 800px;
line-height: 1.6;
}
.nav-toggle {
position: fixed;
top: 20px;
right: 20px;
z-index: 100;
background: rgba(255, 255, 255, 0.3);
border: none;
color: #fff;
padding: 10px 20px;
border-radius: 30px;
font-size: 1rem;
cursor: pointer;
backdrop-filter: blur(10px);
transition: all 0.3s ease;
}
.nav-toggle:hover {
background: rgba(255, 255, 255, 0.5);
}
nav {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100vh;
background: rgba(255, 255, 255, 0.8);
backdrop-filter: blur(10px);
z-index: 99;
transform: translateY(-100%);
transition: transform 0.5s ease;
overflow: hidden;
}
.active nav {
transform: translateY(0);
}
.nav-links {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100%;
padding: 0 50px;
}
.nav-links a {
color: #333;
text-decoration: none;
font-size: 2rem;
margin: 20px 0;
padding: 10px 20px;
border-radius: 30px;
transition: all 0.3s ease;
position: relative;
}
.nav-links a:hover {
background: rgba(0, 0, 0, 0.1);
}
.nav-links a::after {
content: '';
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
width: 0;
height: 2px;
background: #333;
transition: width 0.3s ease;
}
.nav-links a:hover::after {
width: 80%;
}
/* 毛玻璃效果在导航菜单上 */
nav {
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
background: rgba(255, 255, 255, 0.8);
}
</style>
</head>
<body>
<header>
<div class="content">
<h1>欢迎来到我的网站</h1>
<p>这是一个展示毛玻璃特效导航菜单的示例页面,点击右上角的菜单按钮可以体验全屏导航效果。</p>
<p>更多内容请访问:<a href="http://www.zhaosf.pub" target="_blank">www.zhaosf.pub</a></p>
</div>
<button class="nav-toggle">菜单</button>
<nav id="navMenu">
<div class="nav-links">
<a href="#home">首页</a>
<a href="#about">关于</a>
<a href="#services">服务</a>
<a href="#portfolio">作品</a>
<a href="#contact">联系</a>
</div>
</nav>
</header>
<script>
document.addEventListener('DOMContentLoaded', function() {
const navToggle = document.querySelector('.nav-toggle');
const nav = document.getElementById('navMenu');
navToggle.addEventListener('click', function() {
nav.classList.toggle('active');
if (nav.classList.contains('active')) {
navToggle.textContent = '关闭';
} else {
navToggle.textContent = '菜单';
}
});
// 点击导航链接时关闭菜单
const navLinks = document.querySelectorAll('.nav-links a');
navLinks.forEach(link => {
link.addEventListener('click', function() {
nav.classList.remove('active');
navToggle.textContent = '菜单';
});
});
// 滚动时关闭菜单
window.addEventListener('scroll', function() {
if (nav.classList.contains('active')) {
nav.classList.remove('active');
navToggle.textContent = '菜单';
}
});
});
</script>
</body>
</html>
HTML5上下左右轮盘菜单导航代码
于 2025-04-19 14:39:56 首次发布