drawer slide in from right - final

by ian_smithz

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-touch-events/2.0.0/jquery.mobile-events.min.js"></script>
<div class="drawer-container">
  inital content
  <div class="drawer">

    <div class="drawer-handle"><span class="drawer-arrow"></span></div>

    <div class="drawer-content">
      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquid laboriosam tempore porro minima saepe culpa consectetur. Impedit ipsa quisquam tenetur cumque odit cum aliquam enim inventore asperiores perferendis quos quaerat.</p>
    </div>

  </div>
</div>

CSS

.drawer-container {
  height: 300px;
  background-color: #000;
  position: relative;
  color: white;
  margin: 0 auto;
  max-width: 500px;
  overflow: hidden;
}

.drawer {
  position: absolute;
  transition: left 1s;
  left: calc(100% - 40px);
  top: 0;
  height: 100%;
  width: 100%;
}

.expanded .drawer {
  transition: left 1s;
  left: 0;
}

.drawer-handle {
  width: 40px;
  background-color: red;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

@media (min-width: 1025px) {
  
  .drawer-handle {
    display: none;
  }
}

.drawer-content {
  position: absolute;
  top: 0;
  left: 40px;
  bottom: 0;
  min-width: 200px;
  background-color: #f5f5f5;
  color: #333;
  box-shadow: 0 4px 6px -2px rgba(0,0,0,.2);
}

.drawer-arrow:before {
  content: "";
  display: block;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 15px 18px 15px 0;
  border-color: transparent #000000 transparent transparent;
  /*transition: transform 1s;*/
  transform: rotate(0deg);
}

.expanded .drawer-arrow:before {
  /*transition: transform 1s;*/
  transform: rotate(180deg);
}

JavaScript

$(document).ready(function() {

    $('.drawer-handle').on('click swipe', function () {
        $('.drawer-container').toggleClass('expanded');
    });

});