以下是一个使用 JavaScript 实现全屏导航的示例代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
/* 样式可根据需要进行调整 */
body {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
}
.nav {
display: flex;
justify-content: space-around;
background-color: #333;
padding: 10px 0;
}
.nav a {
color: #fff;
text-decoration: none;
font-size: 20px;
}
/* 全屏样式 */
.fullscreen {
width: 100vw;
height: 100vh;
position: fixed;
top: 0;
left: 0;
background-color: rgba(0, 0, 0, 0.5);
display: none; /* 初始隐藏 */
z-index: 1000;
}
.fullscreen-content {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: #fff;
padding: 20px;
border-radius: 5px;
}
</style>
</head>
<body>
<div class="nav">
<a href="#" id="openFullscreen">打开全屏导航</a>
</div>
<div class="fullscreen" id="fullscreen">
<div class="fullscreen-content">
<a href="#" id="closeFullscreen">关闭</a>
<ul>
<li><a href="#">首页</a></li>
<li><a href="#">关于我们</a></li>
<li><a href="#">服务</a></li>
<li><a href="#">联系我们</a></li>
</ul>
</div>
</div>
<script>
const openBtn = document.getElementById('openFullscreen');
const closeBtn = document.getElementById('closeFullscreen');
const fullscreen = document.getElementById('fullscreen');
openBtn.addEventListener('click', () => {
fullscreen.style.display = 'block';
});
closeBtn.addEventListener('click', () => {
fullscreen.style.display = 'none';
});
</script>
</body>
</html>
在上述代码中:
可能出现的问题及解决方法:
没有搜到相关的文章