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);
  lef.........完整代码请登录后点击上方下载按钮下载查看

网友评论0