简单实现H5好看的菜单栏

字体图标需要自己去引用别的
样式文件自己再改改路径

在这里插入图片描述
在这里插入图片描述

<!DOCTYPE html>
<html lang="zh-CN">

<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">
	<title>菜单栏</title>
	<link rel="stylesheet" href="./css/dist/home.css">
	<link rel="stylesheet" href="./font/all.css">
	<link rel="stylesheet" href="./font/font-awesome.css">
</head>
<style>

</style>

<body>
	<div class="nav">
		<div class="menuToggle"></div>
		<ul class="menu">
			<li class="list active">
				<a href="#" style="--clr:#f1662a">
					<span class="icon">
					 <i class="fas fa-home" ></i>
					</span>
					<span class="text">
						home
					</span>
				</a>
			</li>
			<li class="list">
				<a href="#" style="--clr:#3b9e4f">
					<span class="icon">
						<i class="fas fa-user" ></i>
					</span>
					<span class="text">
						about
					</span>
				</a>
			</li>
			<li class="list">
				<a href="#" style="--clr:#fcc62a">
					<span class="icon">
				
						<i class="fas fa-comment" ></i>
					</span>
					<span class="text">
						massage
					</span>
				</a>
			</li>
			<li class="list">
				<a href="#" style="--clr:#33a9dc">
					<span class="icon">
						<i class="fas fa-camera" ></i>
					</span>
					<span class="text">
						photos
					</span>
				</a>
			</li>
			<li class="list">
				<a href="#" style="--clr:#ffe660">
					<span class="icon">
						<i class="fas fa-cog" ></i>
					</span>
					<span class="text">
						setting
					</span>
				</a>
			</li>
		</ul>
	</div>
</body>
<script>
	//获取侧边栏外部dom
	var nav = document.querySelector(".nav");
	var menuToggle = document.querySelector(".menuToggle");
	var list = document.querySelectorAll(".list");
	//设置点击事件
	menuToggle.addEventListener("click", function () {
		nav.classList.toggle("active");
	});
	list.forEach( item => {
		item.addEventListener("click", function (e) {
			list.forEach(item =>{
				item.classList.remove("active");
			   this.classList.add("active");
			})
		});
	})

</script>
</html>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
body {
  min-height: 100vh;
  background: #2f323f;
}
.nav {
  position: fixed;
  inset: 40px 0 40px 20px;
  background: #fff;
  width: 75px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  transition: 0.5s;
}
.nav .menuToggle {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 60px;
  padding: 0 25px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.25);
  display: flex;
  align-items: center;
  justify-content: flex-start;
  cursor: pointer;
}
.nav .menuToggle::before {
  content: '';
  position: absolute;
  width: 30px;
  height: 2px;
  background: #333;
  transform: translateY(-8px);
  transition: 0.5s;
}
.nav .menuToggle::after {
  content: '';
  position: absolute;
  width: 30px;
  height: 2px;
  background: #333;
  transform: translateY(8px);
  box-shadow: 0 -8px 0 #333;
  transition: 0.5s;
}
.nav ul {
  display: flex;
  flex-direction: column;
  width: 100%;
}
.nav ul li {
  list-style: none;
  position: relative;
  width: 100%;
  height: 76px;
  border-radius: 12px;
  border: 8px solid transparent;
  transition: 0.5s;
}
.nav ul li::before {
  content: '';
  position: absolute;
  top: -28px;
  right: -10px;
  width: 20px;
  height: 20px;
  background: transparent;
  border-bottom-right-radius: 20px;
  box-shadow: 6px 7px 0 5px #2f323f;
  transform: scale(0);
  transform-origin: bottom right;
  transition: 0.5s;
}
.nav ul li::after {
  content: '';
  position: absolute;
  bottom: -28px;
  right: -10px;
  width: 20px;
  height: 20px;
  background: transparent;
  border-top-right-radius: 20px;
  box-shadow: 6px -6px 0 3px #2f323f;
  transform: scale(0);
  transform-origin: bottom right;
  transition: 0.5s;
}
.nav ul li a {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  text-decoration: none;
  z-index: 100;
}
.nav ul li a .icon {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 60px;
  height: 60px;
  border-radius: 10px;
  font-size: 1.75rem;
  line-height: 60px;
  border: 6px solid transparent;
  transition: 0.5s;
}
.nav ul li a .icon i {
  font-size: 24px;
}
.nav ul li a .icon::before {
  content: '';
  position: absolute;
  top: 12px;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--clr);
  filter: blur(8px);
  opacity: 0;
  transition: 0.5s;
}
.nav ul li a .icon::after {
  content: '';
  position: absolute;
  top: 10px;
  left: -62px;
  width: 15px;
  height: 15px;
  background: var(--clr);
  border-radius: 50%;
  border: 8px solid #2f323f;
}
.nav ul li a .text {
  position: relative;
  display: flex;
  align-items: center;
  padding: 0 15px;
  height: 60px;
  opacity: 0;
  visibility: hidden;
  transition: 0.5s;
  color: #333;
}
.nav ul li.active {
  transform: translateX(30px);
  background-color: #2f323f;
}
.nav ul li.active::before {
  right: 22px;
  transform: scale(1);
}
.nav ul li.active::after {
  right: 22px;
  transform: scale(1);
}
.nav ul li.active .icon {
  color: #fff;
  background: var(--clr);
}
.nav ul li.active .icon::before {
  opacity: 0.5;
}
.nav ul li.active .text {
  color: #fff;
}
.nav.active .menuToggle::before {
  transform: translateY(0px) rotate(45deg);
}
.nav.active .menuToggle::after {
  transform: translateY(0px) rotate(-45deg);
  box-shadow: 0 0 0 #3333;
}
.nav.active ul li a .text {
  opacity: 1;
  visibility: visible;
}
.nav.active {
  width: 250px;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值