CSS实现移动端侧滑

[html]  view plain  copy
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4.     <title>app-menu</title>  
  5.     <style type="text/css">  
  6.         .menu {  
  7.             position: fixed;  
  8.             left: 0;  
  9.             top: 0;  
  10.             width: 100%;  
  11.             height: 100%;  
  12.             overflow: hidden;  
  13.             pointer-events: none;  
  14.             z-index: 150;  
  15.         }  
  16.         .menu--visible {  
  17.             pointer-events: auto;  
  18.         }  
  19.         .app-menu {  
  20.             background-color: #fff;  
  21.             color: #fff;  
  22.             position: relative;  
  23.             /*max-width: 400px;*/  
  24.             width: 80%;  
  25.             height: 100%;  
  26.             background-color: #ddd;  
  27.             box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);  
  28.             -webkit-transform: translateX(-103%);  
  29.                     transform: translateX(-103%);  
  30.             display: flex;  
  31.             flex-direction: column;  
  32.             will-change: transform;  
  33.             z-index: 160;  
  34.             pointer-events: auto;  
  35.   
  36.             transition: all 0.5s ease-in;  
  37.             transition: all 0.4s ease-out;              
  38.         }  
  39.         .menu--visible .app-menu {  
  40.             -webkit-transform: none;  
  41.                     transform: none;  
  42.         }  
  43.         .menu:after {  
  44.             content: '';  
  45.             display: block;  
  46.             position: absolute;  
  47.             left: 0;  
  48.             top: 0;  
  49.             width: 100%;  
  50.             height: 100%;  
  51.             background: rgba(0,0,0,0.4);  
  52.             opacity: 0;  
  53.             will-change: opacity;  
  54.             pointer-events: none;  
  55.             transition: opacity 1s cubic-bezier(0,0,0.3,1);  
  56.         }  
  57.         .menu--visible.menu:after {  
  58.             opacity: 1;  
  59.             pointer-events: auto;  
  60.         }  
  61.         /* aux */  
  62.         body {  
  63.           margin: 0;  
  64.         }  
  65.         .layout {  
  66.           width: 100%;  
  67.         }  
  68.         .header {  
  69.           background-color: #ccc;  
  70.         }  
  71.         .menu-icon {  
  72.           background-color: #b34848;  
  73.           width: 100px;  
  74.           height: 100px;  
  75.         }  
  76.     </style>  
  77. </head>  
  78. <body>  
  79. <div class="menu">  
  80.     <div class="app-menu"></div>  
  81. </div>  
  82. <div class="layout">  
  83.     <div class="header">  
  84.         <div class="menu-icon"></div>  
  85.     </div>  
  86. </div>  
  87. </body>  
  88. <script src="http://webpic.my4399.com/o2o/js/jquery-2.1.4.min.js"></script>  
  89. <script type="text/javascript">  
  90.     function toggleClassMenu() {    
  91.         if(!myMenu.classList.contains("menu--visible")) {         
  92.             myMenu.classList.add("menu--visible");  
  93.         } else {  
  94.             myMenu.classList.remove('menu--visible');         
  95.         }     
  96.     }  
  97.   
  98.   
  99.     var myMenu = document.querySelector(".menu");  
  100.     var oppMenu = document.querySelector(".menu-icon");  
  101.     oppMenu.addEventListener("click", toggleClassMenu, false);  
  102.     myMenu.addEventListener("click", toggleClassMenu, false);  
  103. </script>  
  104. </html>  


参考网站:http://www.zcfy.cc/article/smooth-as-butter-achieving-60-fps-animations-with-css3-1054.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值