Skills/JavaScript

221115 ham_menu03.html (open, close 버튼 만들기)

개발자 윤구나 2022. 11. 15. 12:47
<!DOCTYPE html>
<html lang="ko">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>ham_menu</title>
    <script src="https://code.jquery.com/jquery-3.6.1.min.js"></script>
    <script>
      $(function () {
        const btnOpen = $(".header .lnb .btn_open");
        const btnClose = $(".header .lnb .btn_close");
        const listMenu = $(".header .list_menu");

        $(btnOpen).click(function () {
          $(listMenu).stop().animate(
            {
              height: 300,
            },
            300
          );
          btnOpen.css("display", "none");
          btnClose.css("display", "block");
        });
        $(btnClose).click(function () {
          $(listMenu).stop().animate(
            {
              height: 0,
            },
            300
          );
          btnOpen.css("display", "block");
          btnClose.css("display", "none");
        });
      });
    </script>
    <style>
      * {
        margin: 0;
        padding: 0;
      }

      li {
        list-style: none;
      }

      .lnb {
        width: 1050px;
        height: 50px;
        color: white;
        background-color: black;
        margin: 0 auto;
        overflow: hidden;
      }

      .lnb .btn {
        width: 50px;
        height: 50px;
        background-color: seagreen;
        text-align: center;
        line-height: 50px;
        float: left;
        cursor: pointer;
      }

      .lnb .btn_close {
        display: none;
      }

      .lnb li {
        width: 200px;
        height: 50px;
        text-align: center;
        line-height: 50px;
        float: left;
      }

      .list_menu {
        width: 100%;
        height: 0;
        font-size: 50px;
        text-align: center;
        line-height: 300px;
        border: 1px solid black;
        box-sizing: border-box;
        overflow: hidden;
      }
    </style>
  </head>
  <body>
    <header class="header">
      <nav class="lnb">
        <div class="btn_open btn">열기</div>
        <div class="btn_close btn">닫기</div>
        <ul>
          <li>menu01</li>
          <li>menu02</li>
          <li>menu03</li>
          <li>menu04</li>
          <li>menu05</li>
        </ul>
      </nav>
      <div class="list_menu">full_down_menu</div>
    </header>
  </body>
</html>