svg+js实现可折叠左侧垂直菜单导航条效果代码

代码语言:html

所属分类:菜单导航

代码描述:svg+js实现可折叠左侧垂直菜单导航条效果代码

代码标签: svg js 折叠 左侧 垂直 菜单 导航条

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

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

<head>
    <meta charset="utf-8">
    <title>Sidebar</title>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Work+Sans&display=swap" rel="stylesheet">
  <style>

 :root {
  --primary-color: #191919;
  --primary: #408CF9;
  --white: #FFFFFF;
  --sidebar-primary-hover: #2B2B2F;
  --sidebar-background: #141318;
  --background: #F3F5F6;
  --text-link: #FFFFFF;
  --expand-button: #408CF9;
  --logout: #FA7575;
  --search-background: #2B2B2F;
}

body {
  font-family: 'Work Sans', sans-serif;
  font-size: 16px;
  padding: 1rem;
  height: 100%;
  background: var(--background);
}

html {
  height: 100%;
}

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

.sidebar {
  position: sticky;
  top: 0;
  left: 0;
  min-height: 50rem;
  height: 100%;
  padding: 1.5rem 1rem;
  border-radius: 1.5rem;
  user-select: none;
  max-width: 18rem;
  min-width: 4rem;
  display: flex;
  color: var(--white);
  flex-direction: column;
  background-color: var(--sidebar-background);
  transition: max-width 0.2s ease-in-out;
}

body.collapsed .sidebar {
  max-width: 5rem;
  display: flex;
}

body.collapsed .hide {
  position: absolute;
  visibility: hidden;
}

/*? search wrapper */
.search__wrapper {
  position: relative;
}

.search__wrapper input {
  background-color: var(--search-background);
  min-height: 3rem;
  width: 100%;
  color: var(--text-link);
  border-radius: 0.75rem;
  padding-left: 2.75rem;
  font-size: 1.4rem;
  border: none;
}

.search__wrapper svg {
  position: absolute;
  z-index: 2;
  top: 50%;
  left: 0.75rem;
  width: 1.5rem;
  height: 1.5rem;
  stroke: var(--text-link);
  transform: translateY(-50%);
  pointer-events: none;
}

/*? sidebar top */
.sidebar-top-wrapper {
  display: flex;
  background-color: var(--primary-color-light);
}

.sidebar-top {
  position: relative;
  display: flex;
  align-items: start;
  justify-content: center;
  flex-direction: column;
  overflow: hidden;
  height: 4rem;
  padding-bottom: 1rem;
}

.logo__wrapper {
  display: flex;
  align-items: center;
  color: var(--text-link);
  font-weight: 700;
  text-decoration: none;
  font-size: 1.35rem;
  padding: 0 0.6rem;
  gap: 0.75rem;
}

.logo-small {
  height: 2rem;
  width: 2rem;
  overflow: hidden;
  object-fit: cover;
}

.company-name {
  white-space: nowrap;
}

/*? menu links */
.sidebar-links {
  margin-top: 1rem;
}

.sidebar-links ul {
  list-style-type: none;
  position: relative;
  display: flex;
  row-gap: 0.5rem;
  flex-direction: column;
}

.sidebar-links li {
  color: var(--text-link);
  min-width: 3rem;
}

.sidebar-links li svg {
  stroke: var(--text-link);
  width: 1.75rem;
  height: 1.75rem;
  min-width: 1.75rem;
}

.sidebar-links li a:hover {
  background-color: var(--sidebar-primary-hover);
}

.sidebar-links li a {
  color: var(--text-link);
  width: 100%;
  padding-left: 0.6rem;
  font-size: 1.25rem;
  display: flex;
  gap: 0.75rem;
  border-radius: 0.75rem;
  justify-content: start;
  align-items: center;
  min-height: 3.25rem;
  text-decoration: none;
  transition: background-color 0.2s ease-in-out;
}

.sidebar-links li a .link {
  overflow: hidden;
  white-space: nowrap;
  animation: fadeIn 0.2s ease-in-out;
}

.sidebar-links .active:hover {
  background-color: var(--sidebar-primary-hover);
}

.sidebar-links .active {
  text-decoration: none;
  background-color: var(--sidebar-primary-hover);
  color: var(--text-link);
}

.sidebar-links .active svg {
  stroke: var(--text-link);
}

/* ?tooltip */
.tooltip {
  position: relative;
}

.tooltip .tooltip__content::after {
  content: " ";
  position: absolute;
  top: 50%;
  left: 0%;
  margin-left: -9px;
  margin-top: -5px;
  border-width: 5px;
  border-style: solid;
  border-color: transparent var(--primary-color) transparent transparent;
}

.tooltip .tooltip__content {
  visibility: hidden;
  background-color: var(--primary-color);
  color: var(--white);
  text-align: center;
  border-radius: 6px;
  padding: 0.35rem 0.75rem;
  position: absolute;
  z-index: 1;
  left: 4.5rem;
}

.collapsed .tooltip:hover .tooltip__content {
  visibility: visible;
}

.collapsed .tooltip:focus .tooltip__content {
  visibility: visible;
}

/*? profile part */
.sidebar__profile {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-direction: row;
  color: var(--text-link);
  overflow-x: hidden;
  min-height: 2.5rem;
  margin-top: auto;
}

.avatar__wrapper {
  position: relative;
  display: flex;
}

.avatar {
  display: block;
  width: 3rem;
  height: 3rem;
  object-fit: cover;
  cursor: pointer;
  border-radius: 50%;
  border: 3px solid transparent;
  transition: all 0.2s ease-in-out;
}

.avatar:hover {
  border: 3px solid var(--primary);
}

.avatar__name {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  white-space: nowrap;
}

.user-name {
  font-weight: 600;
  text-align: left;
  color: var(--text-link);
}

.email {
  color: var(--text-link);
  font-size: 0.8rem;
}

.logout {
  margin-left: auto;
}

.logout svg {
  color: var(--logout);
}

/*? Expand button */
.expand-btn {
  position: absolute;
  display: grid;
  place-items: center;
  cursor: pointer;
  background-color: var(--expand-button);
  z-index: 2;
  right: -1rem;
  width: 2.25rem;
  height: 2.25rem;
  border: none;
  border-radius: 50%;
}

.expand-btn svg {
  transform: rotate(-180deg);
  stroke: var(--white);
  width: 1.25rem;
  height: 1.25rem;
}

body.collapsed .expand-btn svg {
  transform: rotate(-360deg);
}

@keyframes fadeIn {
  from {
    width: 4rem;
    opacity: 0;
  }

  to {
    opacity: 1;
    width: 100%;
  }
}
  </style>
</head>

<body>
    <nav class="sidebar">
        <div class="sidebar-top-wrapper">
            <div class="sidebar-top">
                <a href="#" class="logo__wrapper">
                    <img src="//repo.bfw.wiki/bfwrepo/image/60d41f5173b0d.png?x-oss-process=image/auto-orient,1/resize,m_fill,w_100,h_100,/quality,q_90" alt="Logo" class="logo-small">
                    <span class="hide company-name">
            Aurora Wealth
          </span>
                </a>
            </div>
            <button class="expand-btn" type="button">
        <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg" aria-labelledby="exp-btn" role="img">
          <title id="exp-btn">Expand/Collapse Menu</title>
          <path d="M6.00979 2.72L10.3565 7.06667C10.8698 7.58 10.8698 8.42 10.3565 8.93333L6.00979 13.28"
            stroke-width="1.5" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round" />
</svg>
      </button>
        </div>
        <div class="search__wrapper">
            <svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg" aria-labelledby="search-icon" role="img">
        <title id="search-icon">Search</title>
        <path
          d="M9 9L13 13M5.66667 10.3333C3.08934 10.3333 1 8.244 1 5.66667C1 3.08934 3.08934 1 5.66667 1C8.244 1 10.3333 3.08934 10.3333 5.66667C10.3333 8.244 8.244 10.3333 5.66667 10.3333Z"
          stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" />
      </svg>
            <input type="text" aria-labelledby="search-icon">
        </div>
        <div class="sidebar-links">
            <ul>
                <li>
                    <a href="#dashboard" title="Dashboard" class="tooltip">
                        <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-layout-dashboard" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
              <path stroke="none" d="M0 0h24v24H0z" fill="none" />
              <path d="M4 4h6v8h-6z" />
              <path d="M4 16h6v4h-6z" />
              <path d="M14 12h6v8h-6z" />
              <path d="M14 4h6v4h-6z" />
            </svg>
                        <span class="link hide">Dashboard</span>
                        <span class="tooltip__content">Dashboard</span>
                    </a>
                </li>
                <li>
                    <a href="#market-overview" class="tooltip">
                        <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-chart-bar" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" aria-hidden="tr.........完整代码请登录后点击上方下载按钮下载查看

网友评论0