WEBデザインの勉強

WEB制作初心者が1から勉強するブログ。

ドロワーメニュー

f:id:mmmmofu:20170430002530p:plain

デモ
http://efu.sakura.ne.jp/web/drawermenu/

<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <title>ドロワーメニュー</title>
  <link rel="stylesheet" href="style.css">
  <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
  <script src="script.js"></script>
</head>
<body>
  <div class="content">
    <h1>ドロワーメニュー</h1>
    <p class="menu">MENU</p>
  </div>
  <div class="overlay"></div>
  <nav>
    <ul>
      <li><a href="#">TOP</a></li>
      <li><a href="#">TABOUT</a></li>
      <li><a href="#">TCONTACT</a></li>
    </ul>
    <p class="close"><span>CLOSE</span></p>
  </nav>
</body>
</html>
html, body, nav, ul, li, div, h1, p {
  margin: 0;
  padding: 0;
  line-height: 1.0;
}

body {
  width: 100%;
  overflow-x: hidden;
}

a {
  color: #FFF;
  text-decoration: none;
  -webkit-transition: all .3s linear;
  -o-transition: all .3s linear;
  transition: all .3s linear;
}

a:hover {
  color: #F7AF1D;
}

.overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.4);
}

nav {
  position: fixed;
  top: 0;
  left: 0;
  width: 300px;
  height: 100%;
  background: #096148;
  transform: translateX(-320px);
  -webkit-transition: all .3s cubic-bezier(0.23, 1, 0.32, 1);
  -o-transition: all .3s cubic-bezier(0.23, 1, 0.32, 1);
  transition: all .3s cubic-bezier(0.23, 1, 0.32, 1);
}

nav ul {
  margin-top: 50px;
}

nav ul li {
  text-align: center;
  padding: 10px 0;
  color: #FFF;
  letter-spacing: 0.1em;
}

nav.active {
  transform: translateX(0);
}

nav .close {
  position: absolute;
  bottom: 100px;
  right: -20px;
  background: #096148;
  width: 20px;
  height: 100px;
  color: #FFF;
  cursor: pointer;
}

nav .close span {
  display: block;
  -webkit-transform: rotate(90deg);
  -ms-transform: rotate(90deg);
  -o-transform: rotate(90deg);
  transform: rotate(90deg);
  font-size: 10px;
  padding: 30px 0;
  letter-spacing: 0.2em;
  -webkit-transition: all .3s linear;
  -o-transition: all .3s linear;
}

nav .close:hover span {
  color: #F7AF1D;
}

.content {
  position: relative;
  width: 100%;
  height: 3000px;
  -webkit-transition: all .3s cubic-bezier(0.23, 1, 0.32, 1);
  -o-transition: all .3s cubic-bezier(0.23, 1, 0.32, 1);
  transition: all .3s cubic-bezier(0.23, 1, 0.32, 1);
}

.content.active {
  transform: translateX(320px);
}

.menu {
  position: absolute;
  top: 20px;
  left: 20px;
  width: 50px;
  height: 50px;
  text-align: center;
  font-size: 14px;
  letter-spacing: 0.08em;
  cursor: pointer;
  background: #096148;
  color: #FFF;
  padding: 20px 0;
  box-sizing: border-box;
  font-size: 10px;
  -webkit-transition: all .3s linear;
  -o-transition: all .3s linear;
  transition: all .3s linear;
}

.menu:hover {
  color: #F7AF1D;
}

h1 {
  padding-top: 20px;
  text-align: center;
}
$(function(){
  $('.menu').on('click', function(){
    $('nav').addClass('active');
    $('.content').addClass('active');
    $('.overlay').fadeIn(400);
  });

  $('.overlay, .close').on('click', function(){
    $('nav').removeClass('active');
    $('.content').removeClass('active');
    $('.overlay').fadeOut(300);
  });
});