js+css实现滑动图标导航菜单效果代码

代码语言:html

所属分类:菜单导航

代码描述:js+css实现滑动图标导航菜单效果代码

代码标签: js css 滑动 图标 导航 菜单

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  

  
  
<style>
nav{
  --_nav-trans-speed: 300ms;
  
  --_nav-txt-clr: rgba(255 255 255 / .9);
  --_nav-txt-clr-hover: rgba(255 255 255 / 1);
  --_nav-bg-clr: transparent;
  --_nav-bg-clr-hover: rgba(255 255 255 / .15);
  --_nav-border-clr: rgba(255 255 255 / .25);
  --_nav-border-clr-hover: rgba(255 255 255 / .25);
  
  --_nav-indicator-width: 0px;
  --_nav-indicator-clr: var(--clr-secondary);
  --_nav-indicator-opacity: 1;
  --_nav-indicator-left: 0;
  --_nav-indicator-right: 0;
  --_nav-indicator-top: 0;
  --_nav-indicator-bottom: 0;
  
  display: flex;
  flex-direction: column;
  gap: .5rem;
  position: relative;
}
@media (min-width: 720px){
  nav{
    flex-direction: row;  
  }
}
nav::after{
  content: '';
  position: absolute;
  top: var(--_nav-indicator-top);
  bottom: var(--_nav-indicator-bottom);
  left: var(--_nav-indicator-left);
  right: var(--_nav-indicator-right);
  z-index: -1;
  width: auto;
  height: auto;
  border-radius: 5px;
  transition: left,right,top, bottom, opacity;
  transition-duration: var(--_nav-trans-speed);
  transition-timing-function: ease-in-out;
  background-color: var(--_nav-indicator-clr);
  translate: var(--_nav-indicator-x, 0);
  opacity: var(--_nav-indicator-opacity, 1);
}

nav > a{
  position: relative;
  cursor: pointer;
  text-decoration: none;
  color: var(--_nav-txt-clr);
  background-color: transparent;
  border: 1px solid var(--_nav-border-clr);
  border-radius: 5px;
  padding: .5rem .75rem;
  display: flex;
  align-items: center;
  gap: .25rem;
/*  mix-blend-mode: luminosity;*/
}
nav > a::before{
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background-color: var(--_nav-bg-clr);
  z-index: -1;
  transition: background-color var(--_nav-trans-speed) ease-in-out;
}



nav > a:hover{
  --_nav-txt-clr: var(--_nav-txt-clr-hover);
  --_nav-bg-clr: var(--_nav-bg-clr-hover);
  --_nav-border-clr: var(--_nav-border-clr-hover);
}
nav svg{
  width: 18px;
}


/* general styling not relevant for this demo */
*,
::before,
::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
:root {
  --clr-bg: #222;
  --clr-primary: #f5f5f5;
  --clr-secondary: #075985; 
}

html {
  background-color: var(--clr-bg);
  font-family: system-ui;
  font-family: system-ui;
}

body {
  min-height: 100svh;
  display: grid;
  place-content: center;
  gap: 1.5rem;
  /*font-size: clamp(0.9rem, 2.5vw,1.4rem);*/
  color: var(--clr-primary);
  padding: 1rem;
  background-image: radial-gradient(circle, rgba(175, 208, 84, .25) 1px, rgba(0, 0, 0, 0) 1px);
  background-size: 40px 40px;
}

h1 {
  font-size: clamp(1rem, 2.5vw + 0.25rem, 1.2rem);
  font-weight: 500;
  line-height: 1.6;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
</style>


  
</head>

<body translate="no">
  <nav>

  <a href="#" title="Home">
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
      <path stroke="none" d="M0 0h24v24H0z" fill="none" />
      <path d="M12.707 2.293l9 9c.63 .63 .184 1.707 -.707 1.707h-1v6a3 3 0 0 1 -3 3h-1v-7a3 3 0 0 0 -2.824 -2.995l-.176 -.005h-2a3 3 0 0 0 -3 3v7h-1a3 3 0 0 1 -3 -3v-6h-1c-.89 0 -1.337 -1.077 -.707 -1.707l9 -9a1 1 0 0 1 1.414 0m.293 11.707a1 1 0 0 1 1 1v7h-4v-7a1 1 0 0 1 .883 -.993l.117 -.007z" />
    </svg>
    Home
  </a>

  <a href="#" title="Profile">
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
      <path stroke="none" d="M0 0h24v24H0z" fill="none" />
      <path d="M12 2a5 5 0 1 1 -5 5l.005 -.217a5 5 0 0 1 4.995 -4.783z" />
      <path d="M14 14a5 5 0 0 1 5 5v1a2 2 0 0 1 -2 2h-10a2 2 0 0 1 -2 -2v-1a5 5 0 0 1 5 -5h4z" />
    </svg>
    Profile
  </a>

  <a href="#" title="Settings">
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
      <path stroke="none" d="M0 0h24v24H0z" fill="none" />
      <path d="M14.647 4.081a.724 .724 0 0 0 1.08 .448c2.439 -1.485 5.23 1.305 3.745 3.744a.724 .724 0 0 0 .447 1.08c2.775 .673 2.775 4.62 0 5.294a.724 .724 0 0 0 -.448 1.08c1.485 2.439 -1.305 5.23 -3.744 3.745a.724 .724 0 0 0 -1.08 .447c-.673 2.775 -4.62 2.775 -5.294 0a.724 .724 0 0 0 -1.08 -.448c-2.439 1.485 -5.23 -1.305 -3.745 -3.744a.724 .724 0 0 0 -.447 -1.08c-2.775 -.673 -2.775 -4.62 0 -5.294a.724 .724 0 0 0 .448 -1.08c-1.485 -2.439 1.305 -5.23 3.744 -3.745a.722 .722 0 0 0 1.08 -.447c.673 -2.775 4.62 -2.775 5.294 0zm-2.647 4.919a3 3 0 1 0 0 6a3 3 0 0 0 0 -6z" />
    <.........完整代码请登录后点击上方下载按钮下载查看

网友评论0