导航菜单

Material Design 风格侧边栏菜单变形效果

阿里云


这是一款使用 CSS3 和少量 jQuery 代码来制作的 Material Design 风格侧边栏菜单变形效果。该侧边栏菜单开始时是一个汉堡包按钮,当用户点击该按钮之后,按钮会变形展开为右侧固定的侧边栏菜单。

HTML 结构

该侧边栏菜单的 HTML 结构如下:

也想出现在这里?联系我们
创客主机
  1. <div class="menu-expanded">
  2.   <div id="menu" class="menu"></div>
  3.   <span class="linee linea1"></span>
  4.   <span class="linee linea2"></span>
  5.   <span class="linee linea3"></span>
  6.   <div class="main-menu">
  7.     <ul>
  8.       <li><a href="#">Home</a></li>
  9.       <li><a href="#">Categories</a></li>
  10.       <li><a href="#">Works</a></li>
  11.       <li><a href="#"><a href="#">Portfolio</a></a></li>
  12.       <li><a href="#">Contact Us</a></li>
  13.       <li><a href="#">About Us</a></li>
  14.     </ul>
  15.   </div>
  16. </div>

CSS 样式

侧边栏菜单的样式如下:

  1. .menu-expanded {
  2.   background-color: transparent;
  3.   position: fixed;
  4.   width: 340px;
  5.   height:100%;
  6.   top: 0px;
  7.   right: 0px;
  8.   overflow: hidden !important;
  9.   z-index: 5;
  10. }
  11.  
  12. .menu {
  13.   float: right;
  14.   margin: 15px 15px 0 0;
  15.   height: 49px;
  16.   width: 49px;
  17.   border-radius: 50%;
  18.   background-color: #EE283D;
  19.   border: none;
  20.   transition: all 0.40s ease-out;
  21. }
  22.  
  23. .main-menu {
  24.   visibility: hidden;
  25.   position: absolute;
  26.   right: 50px;
  27.   top: 160px;
  28.   opacity: 0;
  29.   transition: all 0.300s;
  30.   transition-delay: 0s;
  31. }
  32.  
  33. .main-menu ul {
  34.   list-style-type: none;
  35. }
  36.  
  37. .main-menu ul li {
  38.   margin: 20px 0px;
  39. }
  40.  
  41. .main-menu ul li a {
  42.   float: right;
  43.   text-decoration: none;
  44.   color: transparent;
  45.   background-color: #DB0024;
  46.   margin-top: 20px;
  47. }
  48.  
  49. .main-menu ul li a:hover {
  50.   opacity: 0.7;
  51. }

汉堡包按钮的主要样式如下:

  1. .menu,
  2. .linee {
  3.   cursor: pointer;
  4. }
  5.  
  6. .over {
  7.   transform: scale(100);
  8.   transition: all 0.350s ease-in;
  9.   cursor: default;
  10. }
  11.  
  12. .linea1 {
  13.   background: #fff;
  14.   height: 2px;
  15.   width: 15px;
  16.   position: absolute;
  17.   right: 33px;
  18.   top: 33px;
  19.   transition: all 0.3s;
  20. }
  21.  
  22. .linea2 {
  23.   background: #fff;
  24.   height: 2px;
  25.   width: 15px;
  26.   position: absolute;
  27.   right: 33px;
  28.   top: 38px;
  29.   opacity: 1;
  30.   transition: opacity 0.5s;
  31. }
  32.  
  33. .linea3 {
  34.   background: #fff;
  35.   height: 2px;
  36.   width: 15px;
  37.   position: absolute;
  38.   right: 33px;
  39.   top: 43px;
  40. }
  41.  
  42. .overL1 {
  43.   animation: closetop 1s forwards;
  44.   animation-direction: alternate;
  45.   cursor: pointer;
  46. }
  47.  
  48. .overL2 {
  49.   opacity: 0;
  50.   transition: opacity 0.5s;
  51.   cursor: pointer;
  52. }
  53.  
  54. .overL3 {
  55.   animation: closebottom 1s forwards;
  56.   animation-direction: alternate;
  57.   cursor: pointer;
  58. }

汉堡包按钮变形为侧边栏菜单的 CSS 代码如下:

  1. @keyframes closetop {
  2.   0% {
  3.     transform: translateY(5px) rotate(0deg);
  4.   }
  5.   25% {
  6.     transform: translateY(5px) rotate(0deg);
  7.   }
  8.   75% {
  9.     transform: translateY(5px) rotate(-45deg);
  10.   }
  11.   100% {
  12.     transform: translateY(5px) rotate(-45deg);
  13.   }
  14. }
  15.  
  16. @keyframes closebottom {
  17.   0% {
  18.     transform: translateY(0px) rotate(0deg);
  19.   }
  20.   25% {
  21.     transform: translateY(-5px) rotate(0deg);
  22.   }
  23.   75% {
  24.     transform: translateY(-5px) rotate(45deg);
  25.   }
  26.   100% {
  27.     transform: translateY(-5px) rotate(45deg);
  28.   }
  29. }
  30.  
  31. .overmain {
  32.   visibility: visible;
  33.   opacity: 1;
  34.   transition: all 0.400s;
  35.   transition-delay: 0.370s;
  36. }

JavaScript

该特效使用 jQuery 代码来为按钮点击时切换相应元素的 class。

  1. $('.menu , .linee').on('click', function() {
  2.   $('.menu').toggleClass('over')
  3.   $('.linea1').toggleClass('overL1')
  4.   $('.linea2').toggleClass('overL2')
  5.   $('.linea3').toggleClass('overL3')
  6.   $('.main-menu').toggleClass('overmain')
  7. });

Material Design 风格侧边栏菜单变形效果

已有 379 人购买
  • hslj
查看演示升级 VIP立刻购买

演示地址 下载地址
收藏
(0)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!