js css html 显示隐藏侧边菜单

<html>

<head>
  <style>
    body {
      margin: 0;
      padding: 0;
    }

    .header {
      border: 1px solid #AAAAAA;
      height: 100px;
    }

    .container {
      display: flex;
      height: calc(100% - 100px);
      width: 100%;
    }

    .menu {
      position: relative;
      width: 150px;
      height: 100%;
      border: 1px solid #AAAAAA;
    }

    .arrow {
      width: 20px;
      height: 30px;
      line-height: 30px;
      text-align: center;
      position: absolute;
      top: 50%;
      right: 0;
      cursor: pointer;
      background: #B7B7B7;
      color: #FFFFFF;
    }

    ul {
      list-style: none;
      padding: 0;
    }
    ul li {
      width: 100%;
      height: 40px;
      line-height: 40px;
      display: block;
      text-align: center;
      cursor: pointer;
    }
    ul li:hover {
      background: #AAAAAA;
    }

    .content {
      flex: 1;
    }
  </style>
  <script>
    var isShow = true;
    function arrow() {
      isShow = !isShow;
      let menu = document.getElementById('menu');
      let arrow = document.getElementById('arrow');
      if (isShow) {
        menu.style.transform = "translateX(0)";
         menu.style.transition = "all 2s"; // 增加过渡效果
        arrow.style.right = "0";
        arrow.innerText = "<";
      } else {
        menu.style.transform = "translateX(-100%)";
         menu.style.transition = "all 2s"; // 增加过渡效果
        arrow.style.right = "-20px";
        arrow.innerText = ">";
      }
    }
  </script>
</head>

<body>
  <div class="header"></div>
  <div class="container">
    <div id='menu' class="menu">
      <ul>
        <li>菜单一</li>
        <li>菜单二</li>
      </ul>
      <span id="arrow" class="arrow" onclick="arrow()"><</span>
    </div>
    <div class="content">

    </div>
  </div>
</body>

</html>

其他:目前是通过 translateX 来隐藏侧边栏的,也可以结合动画来实现

在这里插入图片描述在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值