记录一个常见的二列布局

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

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>两列布局</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    .header {
      width: 100vw;
      height: 50px;
      background: #e5e5e5;
    }

    .container {
      width: 100vw;
      height: calc(100vh - 50px);
    }

    .left {
      background: #f00;
      position: absolute;
      left: 0;
      top: 50px;
      bottom: 0;
      height: inherit;
      width: 240px;
      transition: width 0.3s ease-in-out;
    }

    .right {
      background: #f90;
      width: auto;
      height: inherit;
      position: absolute;
      left: 240px;
      top: 50px;
      right: 0;
      bottom: 0;
      transition: left 0.3s ease-in-out;
    }

    .container .left.close {
      width: 64px;
    }

    .container .right.close {
      left: 64px;
    }

  </style>
</head>

<body>
  <header class="header">
    <button id="btn">切换按钮</button>
  </header>
  <div class="container">
    <div class="left"></div>
    <div class="right"></div>
  </div>
</body>
<script>
  const btn = document.getElementById('btn');
  const right = document.querySelector('.right');
  const left = document.querySelector('.left');
  let flag = true;
  btn.addEventListener('click', (e) => {
    if (flag) {
      console.log(right.className);
      right.className = `${right.className} close`;
      left.className = `${left.className} close`;
    } else {
      right.className = 'right';
      left.className = 'left';
    }
    flag = !flag;
  })
</script>

</html>

上一篇:[PHP] 理解依赖注入容器-自动注入


下一篇:C# 利用类名字符串调用并执行类方法