<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Responsive Fullscreen Navigation Bar</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
<style>
/* 基本样式 */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: Arial, sans-serif;
}
/* 导航栏样式 */
.navbar {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: #333;
color: #fff;
display: flex;
flex-direction: column;
justify-content: flex-start;
align-items: center;
z-index: 9999;
transform: translateX(-100%);
transition: transform 0.3s ease-in;
}
.navbar.show {
transform: translateX(0%);
}
.navbar .close-btn {
position: absolute;
top: 10px;
right: 10px;
font-size: 18px;
cursor: pointer;
}
.navbar ul {
list-style: none;
margin-top: 30px;
}
.navbar ul li {
margin-bottom: 20px;
}
.navbar ul li a {
color: #fff;
text-decoration: none;
font-size: 16px;
text-transform: uppercase;
transition: color 0.3s ease-in;
display: flex;
align-items: center;
}
.navbar ul li a:hover {
color: #ff0000;
}
/* 导航栏图标样式 */
.navbar ul li i {
margin-right: 10px;
}
/* 汉堡菜单样式 */
.hamburger-menu {
position: absolute;
top: 20px;
left: 20px;
font-size: 30px;
cursor: pointer;
z-index: 9999;
display: none;
}
/* 媒体查询 */
@media only screen and (max-width: 768px) {
.navbar ul li {
margin-bottom: 10px;
}
.navbar ul li a {
font-size: 14px;
}
.hamburger-menu {
display: block;
}
}
</style>
</head>
<body>
<!-- 导航栏 -->
<nav class="navbar" id="navbar">
<div class="close-btn" id="close-btn">
<i class="fas fa-times"></i>
</div>
<ul>
<li><i class="fas fa-home"></i>首页</li>
<li><i class="fas fa-user"></i>关于</li>
<li><i class="fas fa-cog"></i>设置</li>
<li><i class="fas fa-envelope"></i>联系</li>
</ul>
</nav>
<!-- 汉堡菜单 -->
<div class="hamburger-menu" id="hamburger-menu">
<i class="fas fa-bars"></i>
</div>
<script>
const navbar = document.getElementById('navbar');
const hamburgerMenu = document.getElementById('hamburger-menu');
const closeBtn = document.getElementById('close-btn');
hamburgerMenu.addEventListener('click', () => {
navbar.classList.add('show');
});
closeBtn.addEventListener('click', () => {
navbar.classList.remove('show');
});
</script>
</body>
</html>