css+js实现垂直透明伸缩滑动菜单导航条效果代码

代码语言:html

所属分类:菜单导航

代码描述:css+js实现垂直透明伸缩滑动菜单导航条效果代码

代码标签: css js 垂直 透明 伸缩 滑动 菜单 导航条

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

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
    <style>
        :root {
  --bg-one: #090909;
  --bg-two: #424242;
  --sidebar: #070707;
  --selected: #85fcff;
  --text-deselected: #c0c0c0;
  --text-selected: #ffffff;
}

* {
  box-sizing: border-box;
  border: 0;
  margin: 0;
}

html {
  background: url("//repo.bfw.wiki/bfwrepo/image/607e4ca28879b.png") no-repeat center
    center fixed;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  position: relative;
  width: var(--sidebar-width);
  height: 55rem;
  border-radius: 10px;
  transition: width 0.5s ease-in-out;
}

.sidebar::before {
  content: "";
  position: absolute;
  width: var(--sidebar-width);
  height: 55rem;
  background-color: rgb(0 0 0 / 70%);
  border-radius: 10px;
  box-shadow: inset 0 0 0.2rem 0.1rem rgb(154 154 154 / 90%),
    0 0 0.1rem 0.1rem rgb(0 0 0 / 70%);
  opacity: 0.3;
}

.side-border {
  position: absolute;
  width: 0.2rem;
  background-color: var(--selected);
  height: 100%;
  border-radius: 10px;
}

.open-anchor,
.close-anchor {
  position: absolute;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background-color: var(--selected);
  top: 13.7rem;
  left: -0.65rem;
  cursor: pointer;
}

.open-anchor::after {
  content: "";
  position: absolute;
  border-top: 0.4rem solid transparent;
  border-bottom: 0.4rem solid transparent;
  border-left: 0.5rem solid var(--bg-two);
  left: 0.55rem;
  top: 0.35rem;
}

.close-anchor::after {
  content: "";
  position: absolute;
  border-top: 0.4rem solid transparent;
  border-bottom: 0.4rem solid transparent;
  border-right: 0.5rem solid var(--bg-two);
  left: 0.45rem;
  top: 0.35rem;
}

.expand-sidebar {
  position: absolute;
  width: 2rem;
  height: 100%;
  left: calc(var(--sidebar-width) - 0.4rem);
  z-index: 2;
  opacity: 0;
  transition: opacity 0.2s ease-in-out;
}

.expand-sidebar:hover {
  opacity: 1;
}

aside {
  position: absolute;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border-radius: 10px;
}

nav {
  position: absolute;
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 1;
}

ul {
  position: relative;
  padding: 0;
  list-style-type: none;
}

li {
  height: 3.5rem;
}

button,
.deselected-button {
  width: 100%;
  height: 3.5rem;
  background-color: transparent;
  outline: none;
  cursor: pointer;
}

button:hover div > span,
.selected-text {
  color: var(--text-selected);
  opacity: 1;
}

button:hover div > svg {
  stroke: var(--text-selected) !important;
  opacity: 1 !important;
  fill: var(--text-selected);
}

button > div {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  height: 100%;
  padding: 0rem 0rem 0rem 1.25rem;
}

svg {
  /* display: none; */
  width: 2rem;
  fill: white;
  stroke: white;
  width: 2.7rem;
  opacity: 0.5;
  transform-origin: center;
}

ul {
  display: flex;
  flex-direction: column;
  background-color: transparent;
}

ul:nth-child(2) {
  margin: 2.7rem 0;
}

ul:nth-child(2)::after {
  position: absolute;
  content: "";
  width: calc(var(--sidebar-width) / 1.2);
  height: 0.1rem;
  background-color: var(--bg-two);
  top: 8.3rem;
  left: calc(var(--sidebar-width) / 14);
  opacity: 0.7;
  transition: width 0.1s ease-in-out;
}

ul:nth-child(4) {
  margin-top: auto;
  overflow: hidden;
  margin-bottom: 0.5rem;
}

span,
.deselected-text {
  color: var(--text-deselected);
  font-size: 1.2rem;
  opacity: 0.6;
}

.indicator {
  position: absolute;
  width: 0.5rem;
  height: 3.5rem;
  background-color: var(--selected);
  box-shadow: 0 0 0.2rem 0.2rem rgba(0, 0, 0, 0.1),
    0.5rem 0 1.5rem 0.01rem var(--selected);
  left: -0.65rem;
  top: 9.5rem;
  border-radius: 0.3rem 0.25rem 0.25rem 0.3rem;
  transition: top 0.3s ease-in-out;
}

button div {
  pointer-events: none;
}

.badge {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.8rem;
  height: 1.5rem;
  border-radius: 1.5rem;
  background-color: red;
  color: white;
  font-size: 0.9rem;
  left: 14rem;
}

.badge-attached {
  transform: scale(0.7);
  left: 2rem;
  top: 0.1rem;
}

.header {
  display: flex;
  align-items: center;
  height: 3.5rem;
  width: 100%;
}

.name {
  position: absolute;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  font-family: Arial, Helvetica, sans-serif;
  padding: 1rem;
  left: 3.5rem;
  top: 0.4rem;
}

.name > span:nth-child(1) {
  font-weight: bold;
  font-size: 1.2rem;
  color: var(--text-selected);
}

.name > span:nth-child(2) {
  font-size: 0.95rem;
  color: var(--text-selected);
}

.name::before {
  content: "S";
  position: absolute;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 0.5rem;
  background-color: var(--text-deselected);
  left: -2.3rem;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 2.5rem;
  font-weight: bold;
}

@keyframes move-svg {
  0% {
    transform: rotate(10deg);
  }
  50% {
    transform: rotate(20);
  }
  75% {
    transform: rotate(-10deg);
  }
}
    </style>
    </head>
    <body>
     
            
                <div class='sidebar' open='true'>
                    <div class='indicator'></div>
                    <div class='expand-sidebar'>
                        <div class='side-border'></div>
                        <div class='close-anchor'></div>
                    </div>
                    <aside>
                        <nav>
                            <div class='header'>
                                <div class='name'>
                                    <span>Sæbä</span>
                                    <span>Workspace</span>
                                </div>
                            </div>
                            <ul>
                                <li>
                                    <button>
                                        <div id='1'>
                                            <svg>
                                                <use href='#activity'></use>
                                            </svg>
                                            <span>Activity</span>
                                        </div>
                                    </button>
                                </li>
                                <li>
                                    <button>
                                        <div id='2'>
                                            <svg>
                                                <use href='#tasks'></use>
                                            </svg>
                                            <span>My Tasks</span>
                                            <div class='badge'>23</div>
                                        </div>
                                    </button>
                                </li>
                            </ul>
                            <ul>
                                <li>
                                    <button>
                                        <div id='3'>
                                            <svg>
                                                <use href='#overview'></use>
                                            </svg>
                                            <span>Overview</span>
                                        </div>
                                    </button>
                                </li>
                                <li>
                                    <button>
                                        <div id='4'>
                                            <svg>
                                                <use href='#projects'></use>
                                            </svg>
                                            <span>Projects</span>
                                        </div>
                                    </button>
                                </li>
                                <li>
                                    <button>
                                        <div id='5'>
                                            <svg>
                                                <use href='#calendar'></use>
                                            </svg>
                                            <span>Calendar</span>
                                        </div>
                                    </button>
                                </li>
                                <li>
                                    <button>
                                        <div id='6'>
                                            <svg>
                                                <use href='#campaign'></use>
                                            </svg>
                                            <span>Campaign</span>
                                        </div>
                                    </button>
                                </li>
                                <li>
                                    <button>
                                        <div id='7'>
                                            <svg>
                                                <use href='#teams'></use>
                                            </svg>
                                            <span>Teams</span>
                                        </div>
                                    </button>
                                </li>
                                <li>
                                    <button>
                                        <div id='8'>
                                            <svg>
                                                <use href='#analytics'></use>
                                            </svg>
                                            <span>Analytics</span>
                                        </div>
                                    </button>
                                </li>
                                <li>
                                    <button>
                                        <div id='9'>
                                            <svg>
                                                <use href='#billing'></use>
                                            </svg>
                                            <span>Billing</span>
                                        </div>
                                    </button>
                                </li>
                            </ul>
                            <ul>
                                <li>
                                    <button>
                                        <div id='10'>
                                            <svg>
                                                <use href='#help'></use>
                                            </svg>
                                            <span>Help</span>
                                        </div>
                                    </button>
                                </li>
                                <li>
                                    <button>
                                        <div id='11'>
                                            <svg>
                                                <use href='#settings'></use>
                                            </svg>
                                            <span>Settings</span>
                                        </div>
                                    </button>
                                </li>
                            </ul>
                        </nav>
                    </aside>
                    <svg>
                        <symbol id='activity' xmlns="http://www.w3.org/2000/svg" viewBox="5 0 85 65" fill="none">
                            <path d="M52.81 34.76C52.7811 34.5374 52.6924 34.3268 52.5533 34.1507C52.4141 33.9746 52.2298 33.8395 52.02 33.76L35.02 27.37L42.93 6.55996C43.021 6.30655 43.0279 6.0305 42.9494 5.7729C42.8709 5.51531 42.7113 5.28995 42.4944 5.13036C42.2775 4.97078 42.0149 4.8855 41.7456 4.88723C41.4763 4.88896 41.2148 4.9776 41 5.13996L11.65 28.06C11.4768 28.1992 11.3431 28.3815 11.2624 28.5885C11.1817 28.7956 11.1567 29.0202 11.19 29.24C11.2188 29.4625 11.3076 29.6731 11.4467 29.8492C11.5858 30.0253 11.7701 30.1604 11.98 30.24L28.98 36.63L21.07 57.44C20.9789 57.6934 20.9721 57.9694 21.0506 58.227C21.1291 58.4846 21.2886 58.71 21.5055 58.8696C21.7224 59.0291 21.9851 59.1144 22.2543 59.1127C22.5236 59.111 22.7851 59.0223 23 58.86L52.35 35.94C52.5256 35.8028 52.661 35.6208 52.742 35.4131C52.8229 35.2055 52.8464 34.9798 52.81 34.76ZM25 54.15L31.73 36.32C31.8439 36.0095 31.8313 35.6667 31.6947 35.3655C31.5581 35.0643 31.3086 34.8288 31 34.71L15 28.71L39 9.84996L32.29 27.68C32.1749 27.9879 32.1847 28.3286 32.3174 28.6294C32.45 28.9302 32.695 29.1673 33 29.29L49 35.29L25 54.15Z"/>
                        </symbol>
                        <symbol id='tasks' xmlns="http://www.w3.org/2000/svg" viewBox="0 0 41 27">
                            <defs>
                                <style>
                                    .cls-1 {
                                        fill: none;
                                        stroke-linecap: round;
                                        stroke-linejoin: round;
                                        stroke-width: 2px;
                                        opacity: 0.6;
                                    }
                                </style>
                            </defs>
                            <g i.........完整代码请登录后点击上方下载按钮下载查看

网友评论0