2018.7.23 放大缩小菜单

根据项目需求,展示隐藏侧边栏

<html>
  <head>
    <title>最小化动画</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
  </head>
  <style>
    .wrap {
      position:relative;
      height:600px; 
    }
    .bigbox {
      width:400px; 
      height:600px; 
      background:gray; 
    }
    .box {
      position: absolute;
      width: 50px;
      height: 50px;
      background: pink;
      bottom: 0;
      left: 418px;
      cursor: pointer;
    }
    button {
      float: right;
      margin-right: 16px;
      margin-top: 10px;
      cursor: pointer;
    }
    .minimum {
      -webkit-animation: change .5s ease-in-out 1 alternate forwards;
        animation: change .5s ease-in-out 1 alternate forwards;    
    }
    @-webkit-keyframes change {
      from {
        width:400px; 
        height:600px; 
      }
      to {
        width: 50px;
        height: 50px;
        position: absolute;
        bottom: 0;
        left: 418px;
      }
    }
    @keyframes change {
      from {
        width:400px; 
        height:600px; 
        position: absolute;
        top: 0;
        left: 0;
      }
      to {
        width: 0;
        height: 0;
        position: absolute;
        top: 0;
        left: 0;
      }
    }
    .maxmum {
      -webkit-animation: change-back .5s ease-in-out 1 alternate forwards;
        animation: change-back .5s ease-in-out 1 alternate forwards;    
    }
    @-webkit-keyframes change-back {
      from {
        width: 50px;
        height: 50px;
        position: absolute;
        bottom: 0;
        left: 418px;
      }
      to {
        width:400px; 
        height:600px; 
      }
    }
    @keyframes change-back {
      from {
        width: 0;
        height: 0;
        position: absolute;
        top: 0;
        left: 0;
      }    
      to {
        width:400px; 
        height:600px; 
        position: absolute;
        top: 0;
        left: 0;
      }
    }
  </style>
  <body>
      <div class="wrap">
          <div class="bigbox"> <button>最小化</button></div>    
          <div class="box"></div>
      </div>
  </body>
  <script type="text/javascript">

        document.getElementsByTagName("button")[0].onclick = function(){
            this.parentNode.classList.remove("maxmum");
            this.parentNode.classList.add("minimum");
        }

        document.getElementsByClassName("box")[0].onclick = function(){
          // document.getElementsByClassName("bigbox")[0].style.display = "block";
          document.getElementsByClassName("bigbox")[0].classList.remove("minimum");
          document.getElementsByClassName("bigbox")[0].classList.add("maxmum");
        }
      
  </script>
</html>

效果如下:

转载于:https://www.cnblogs.com/yuhanao/p/9354346.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值