魔法导航菜单

效果展示

在这里插入图片描述

CSS 知识点

  • 使用 box-shadow 属性实现不定项曲面

整体页面布局

<div class="navigation">
  <ul>
    <li class="active">
      <a href="#">
        <span class="icon">
          <ion-icon name="home-outline"></ion-icon>
        </span>
      </a>
    </li>
    <li>
      <a href="#">
        <span class="icon">
          <ion-icon name="person-outline"></ion-icon>
        </span>
      </a>
    </li>
    <li>
      <a href="#">
        <span class="icon">
          <ion-icon name="chatbubble-outline"></ion-icon>
        </span>
      </a>
    </li>
    <li>
      <a href="#">
        <span class="icon">
          <ion-icon name="camera-outline"></ion-icon>
        </span>
      </a>
    </li>
    <li>
      <a href="#">
        <span class="icon">
          <ion-icon name="settings-outline"></ion-icon>
        </span>
      </a>
    </li>
    <div class="indicator">
      <span></span>
    </div>
  </ul>
</div>

实现整体容器样式 及 图标元素样式

.navigation {
  width: 420px;
  height: 70px;
  background: #209cff;
  display: flex;
  flex-flow: row wrap;
  justify-content: center;
  align-items: center;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
  border-radius: 10px;
}

.navigation ul {
  position: relative;
  display: flex;
  flex-flow: row wrap;
  width: 350px;
}

.navigation ul li {
  position: relative;
  list-style: none;
  width: 70px;
  height: 70px;
  z-index: 1;
}

.navigation ul li a {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
}

.navigation ul li a .icon {
  position: relative;
  display: block;
  font-size: 1.5em;
  color: #fff;
  line-height: 70px;
  opacity: 0.75;
  transition: 0.5s;
}

.navigation ul li.active a .icon {
  opacity: 1;
  color: #209cff;
  transform: translateY(-8px);
}

实现滑动块样式

.indicator {
  position: absolute;
  top: -10px;
  width: 70px;
  height: 70px;
  background: var(--clr);
  border-bottom-left-radius: 35px;
  border-bottom-right-radius: 35px;
  border: 6px solid var(--clr);
  cursor: pointer;
  transition: 0.5s;
}

.indicator::before {
  content: "";
  position: absolute;
  top: 4px;
  left: -25.75px;
  width: 20px;
  height: 20px;
  background: transparent;
  border-top-right-radius: 16px;
  box-shadow: 4px -6px 0 2px var(--clr);
}

.indicator::after {
  content: "";
  position: absolute;
  top: 4px;
  right: -25.75px;
  width: 20px;
  height: 20px;
  background: transparent;
  border-top-left-radius: 16px;
  box-shadow: -4px -6px 0 2px var(--clr);
}

.indicator span {
  position: absolute;
  bottom: 0px;
  left: -1px;
  width: 60px;
  height: 60px;
  border: 4px solid #209cff;
  border-radius: 50%;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.15);
  transform: scale(0.85);
}

编写导航菜单项点击事件

let list = document.querySelectorAll(".navigation li");

function activeLink() {
  list.forEach((item) => {
    item.classList.remove("active");
    this.classList.add("active");
  });
}

list.forEach((item) => {
  item.addEventListener("click", activeLink);
});

编写导航菜单项滑块移动样式

.navigation ul li:nth-child(2).active ~ .indicator {
  transform: translateX(calc(70px * 1));
}

.navigation ul li:nth-child(3).active ~ .indicator {
  transform: translateX(calc(70px * 2));
}

.navigation ul li:nth-child(4).active ~ .indicator {
  transform: translateX(calc(70px * 3));
}

.navigation ul li:nth-child(5).active ~ .indicator {
  transform: translateX(calc(70px * 4));
}

完整代码下载

完整代码下载

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值